Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support append-only physical table #4716

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/metric-engine/src/engine/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use store_api::metric_engine_consts::{
METADATA_SCHEMA_VALUE_COLUMN_INDEX, METADATA_SCHEMA_VALUE_COLUMN_NAME,
PHYSICAL_TABLE_METADATA_KEY,
};
use store_api::mito_engine_options::{APPEND_MODE_KEY, TTL_KEY};
use store_api::region_engine::RegionEngine;
use store_api::region_request::{AffectedRows, RegionCreateRequest, RegionRequest};
use store_api::storage::consts::ReservedColumnId;
Expand Down Expand Up @@ -426,9 +427,10 @@ impl MetricEngineInner {
// concat region dir
let metadata_region_dir = join_dir(&request.region_dir, METADATA_REGION_SUBDIR);

// remove TTL option
// remove TTL and APPEND_MODE option
let mut options = request.options.clone();
options.remove("ttl");
options.remove(TTL_KEY);
options.remove(APPEND_MODE_KEY);

RegionCreateRequest {
engine: MITO_ENGINE_NAME.to_string(),
Expand Down
2 changes: 2 additions & 0 deletions src/store-api/src/mito_engine_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use common_wal::options::WAL_OPTIONS_KEY;
pub const APPEND_MODE_KEY: &str = "append_mode";
/// Option key for merge mode.
pub const MERGE_MODE_KEY: &str = "merge_mode";
/// Option key for TTL(time-to-live)
pub const TTL_KEY: &str = "ttl";

/// Returns true if the `key` is a valid option key for the mito engine.
pub fn is_mito_engine_option_key(key: &str) -> bool {
Expand Down
50 changes: 50 additions & 0 deletions tests/cases/standalone/common/create/create_metric_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,53 @@ DROP TABLE `auT`;

Affected Rows: 0

-- append-only metric table
CREATE TABLE
phy (ts timestamp time index, val double) engine = metric
with
(
"physical_metric_table" = "",
"append_mode" = "true"
);

Affected Rows: 0

CREATE TABLE t1(ts timestamp time index, val double, host string primary key) engine=metric with ("on_physical_table" = "phy");

Affected Rows: 0

INSERT INTO t1 (ts, val, host) VALUES
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com'),
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com');

Affected Rows: 6

SELECT * FROM t1;

+-------------+---------------------+------+
| host | ts | val |
+-------------+---------------------+------+
| example.com | 2022-01-01T00:00:00 | 1.23 |
| example.com | 2022-01-01T00:00:00 | 1.23 |
| example.com | 2022-01-02T00:00:00 | 4.56 |
| example.com | 2022-01-02T00:00:00 | 4.56 |
| example.com | 2022-01-03T00:00:00 | 7.89 |
| example.com | 2022-01-03T00:00:00 | 7.89 |
+-------------+---------------------+------+

DROP TABLE t1;

Affected Rows: 0

DESC TABLE t1;

Error: 4001(TableNotFound), Table not found: t1

DROP TABLE phy;

Affected Rows: 0

27 changes: 27 additions & 0 deletions tests/cases/standalone/common/create/create_metric_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,30 @@ CREATE TABLE `auT`(
DESC TABLE `auT`;

DROP TABLE `auT`;

-- append-only metric table
CREATE TABLE
phy (ts timestamp time index, val double) engine = metric
with
(
"physical_metric_table" = "",
"append_mode" = "true"
);

CREATE TABLE t1(ts timestamp time index, val double, host string primary key) engine=metric with ("on_physical_table" = "phy");

INSERT INTO t1 (ts, val, host) VALUES
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com'),
('2022-01-01 00:00:00', 1.23, 'example.com'),
('2022-01-02 00:00:00', 4.56, 'example.com'),
('2022-01-03 00:00:00', 7.89, 'example.com');

SELECT * FROM t1;

DROP TABLE t1;

DESC TABLE t1;

DROP TABLE phy;