Skip to content

Commit

Permalink
fix: support append-only physical table
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
  • Loading branch information
waynexia committed Sep 10, 2024
1 parent 545a80c commit f7afebc
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 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 @@ -428,7 +429,8 @@ impl MetricEngineInner {

// remove TTL 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;

0 comments on commit f7afebc

Please sign in to comment.