diff --git a/src/metric-engine/src/engine/create.rs b/src/metric-engine/src/engine/create.rs index dad22c72f9ff..9ca89248dcac 100644 --- a/src/metric-engine/src/engine/create.rs +++ b/src/metric-engine/src/engine/create.rs @@ -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; @@ -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(), diff --git a/src/store-api/src/mito_engine_options.rs b/src/store-api/src/mito_engine_options.rs index 9a6181e64c02..e641a1d2fcda 100644 --- a/src/store-api/src/mito_engine_options.rs +++ b/src/store-api/src/mito_engine_options.rs @@ -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 { diff --git a/tests/cases/standalone/common/create/create_metric_table.result b/tests/cases/standalone/common/create/create_metric_table.result index 37a59598ef91..e1ea76c2bfe1 100644 --- a/tests/cases/standalone/common/create/create_metric_table.result +++ b/tests/cases/standalone/common/create/create_metric_table.result @@ -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 + diff --git a/tests/cases/standalone/common/create/create_metric_table.sql b/tests/cases/standalone/common/create/create_metric_table.sql index a444986e9ee4..749926fb1748 100644 --- a/tests/cases/standalone/common/create/create_metric_table.sql +++ b/tests/cases/standalone/common/create/create_metric_table.sql @@ -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;