mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-27 02:10:38 +00:00
@@ -46,6 +46,8 @@ pub enum MergeMode {
|
||||
LastNonNull,
|
||||
}
|
||||
|
||||
// Note: We need to update [store_api::mito_engine_options::is_mito_engine_option_key()]
|
||||
// if we want expose the option to table options.
|
||||
/// Options that affect the entire region.
|
||||
///
|
||||
/// Users need to specify the options while creating/opening a region.
|
||||
|
||||
@@ -35,6 +35,7 @@ pub fn is_mito_engine_option_key(key: &str) -> bool {
|
||||
"memtable.partition_tree.data_freeze_threshold",
|
||||
"memtable.partition_tree.fork_dictionary_bytes",
|
||||
"append_mode",
|
||||
"merge_mode",
|
||||
]
|
||||
.contains(&key)
|
||||
}
|
||||
|
||||
120
tests/cases/standalone/common/insert/merge_mode.result
Normal file
120
tests/cases/standalone/common/insert/merge_mode.result
Normal file
@@ -0,0 +1,120 @@
|
||||
create table if not exists last_non_null_table(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='last_non_null');
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, 0, NULL), ('host2', 1, NULL, 1);
|
||||
|
||||
Affected Rows: 2
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, NULL, 10), ('host2', 1, 11, NULL);
|
||||
|
||||
Affected Rows: 2
|
||||
|
||||
SELECT * from last_non_null_table ORDER BY host, ts;
|
||||
|
||||
+-------+-------------------------+------+--------+
|
||||
| host | ts | cpu | memory |
|
||||
+-------+-------------------------+------+--------+
|
||||
| host1 | 1970-01-01T00:00:00 | 0.0 | 10.0 |
|
||||
| host2 | 1970-01-01T00:00:00.001 | 11.0 | 1.0 |
|
||||
+-------+-------------------------+------+--------+
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, 20, NULL);
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
SELECT * from last_non_null_table ORDER BY host, ts;
|
||||
|
||||
+-------+-------------------------+------+--------+
|
||||
| host | ts | cpu | memory |
|
||||
+-------+-------------------------+------+--------+
|
||||
| host1 | 1970-01-01T00:00:00 | 20.0 | 10.0 |
|
||||
| host2 | 1970-01-01T00:00:00.001 | 11.0 | 1.0 |
|
||||
+-------+-------------------------+------+--------+
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, NULL, NULL);
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
SELECT * from last_non_null_table ORDER BY host, ts;
|
||||
|
||||
+-------+-------------------------+------+--------+
|
||||
| host | ts | cpu | memory |
|
||||
+-------+-------------------------+------+--------+
|
||||
| host1 | 1970-01-01T00:00:00 | 20.0 | 10.0 |
|
||||
| host2 | 1970-01-01T00:00:00.001 | 11.0 | 1.0 |
|
||||
+-------+-------------------------+------+--------+
|
||||
|
||||
DROP TABLE last_non_null_table;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
create table if not exists last_row_table(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='last_row');
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO last_row_table VALUES ('host1', 0, 0, NULL), ('host2', 1, NULL, 1);
|
||||
|
||||
Affected Rows: 2
|
||||
|
||||
INSERT INTO last_row_table VALUES ('host1', 0, NULL, 10), ('host2', 1, 11, NULL);
|
||||
|
||||
Affected Rows: 2
|
||||
|
||||
SELECT * from last_row_table ORDER BY host, ts;
|
||||
|
||||
+-------+-------------------------+------+--------+
|
||||
| host | ts | cpu | memory |
|
||||
+-------+-------------------------+------+--------+
|
||||
| host1 | 1970-01-01T00:00:00 | | 10.0 |
|
||||
| host2 | 1970-01-01T00:00:00.001 | 11.0 | |
|
||||
+-------+-------------------------+------+--------+
|
||||
|
||||
DROP TABLE last_row_table;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
create table if not exists invalid_merge_mode(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='first_row');
|
||||
|
||||
Error: 1004(InvalidArguments), Invalid options: Matching variant not found at line 1 column 25
|
||||
|
||||
create table if not exists invalid_merge_mode(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='last_non_null', 'append_mode'='true');
|
||||
|
||||
Error: 1004(InvalidArguments), Invalid region options, merge_mode is not allowed when append_mode is enabled
|
||||
|
||||
67
tests/cases/standalone/common/insert/merge_mode.sql
Normal file
67
tests/cases/standalone/common/insert/merge_mode.sql
Normal file
@@ -0,0 +1,67 @@
|
||||
create table if not exists last_non_null_table(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='last_non_null');
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, 0, NULL), ('host2', 1, NULL, 1);
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, NULL, 10), ('host2', 1, 11, NULL);
|
||||
|
||||
SELECT * from last_non_null_table ORDER BY host, ts;
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, 20, NULL);
|
||||
|
||||
SELECT * from last_non_null_table ORDER BY host, ts;
|
||||
|
||||
INSERT INTO last_non_null_table VALUES ('host1', 0, NULL, NULL);
|
||||
|
||||
SELECT * from last_non_null_table ORDER BY host, ts;
|
||||
|
||||
DROP TABLE last_non_null_table;
|
||||
|
||||
create table if not exists last_row_table(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='last_row');
|
||||
|
||||
INSERT INTO last_row_table VALUES ('host1', 0, 0, NULL), ('host2', 1, NULL, 1);
|
||||
|
||||
INSERT INTO last_row_table VALUES ('host1', 0, NULL, 10), ('host2', 1, 11, NULL);
|
||||
|
||||
SELECT * from last_row_table ORDER BY host, ts;
|
||||
|
||||
DROP TABLE last_row_table;
|
||||
|
||||
create table if not exists invalid_merge_mode(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='first_row');
|
||||
|
||||
create table if not exists invalid_merge_mode(
|
||||
host string,
|
||||
ts timestamp,
|
||||
cpu double,
|
||||
memory double,
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY(host)
|
||||
)
|
||||
engine=mito
|
||||
with('merge_mode'='last_non_null', 'append_mode'='true');
|
||||
Reference in New Issue
Block a user