Skip to content

Commit

Permalink
fix: construct correct pk list with pre-existing pk (#3614)
Browse files Browse the repository at this point in the history
* fix: construct correct pk list with pre-existing pk

Signed-off-by: Ruihang Xia <[email protected]>

* update UT

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Apr 7, 2024
1 parent b32e0bb commit b9890ab
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/metric-engine/src/engine/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ impl MetricEngineInner {
request: &RegionCreateRequest,
) -> RegionCreateRequest {
let mut data_region_request = request.clone();
let mut primary_key = vec![ReservedColumnId::table_id(), ReservedColumnId::tsid()];

// concat region dir
data_region_request.region_dir = join_dir(&request.region_dir, DATA_REGION_SUBDIR);
Expand All @@ -416,15 +417,15 @@ impl MetricEngineInner {
.for_each(|metadata| {
if metadata.semantic_type == SemanticType::Tag {
metadata.column_schema.set_nullable();
primary_key.push(metadata.column_id);
}
});

// add internal columns
let [table_id_col, tsid_col] = Self::internal_column_metadata();
data_region_request.column_metadatas.push(table_id_col);
data_region_request.column_metadatas.push(tsid_col);
data_region_request.primary_key =
vec![ReservedColumnId::table_id(), ReservedColumnId::tsid()];
data_region_request.primary_key = primary_key;

// set index options
set_index_options_for_data_region(&mut data_region_request.options);
Expand Down Expand Up @@ -608,7 +609,7 @@ mod test {
assert_eq!(data_region_request.column_metadatas.len(), 4);
assert_eq!(
data_region_request.primary_key,
vec![ReservedColumnId::table_id(), ReservedColumnId::tsid()]
vec![ReservedColumnId::table_id(), ReservedColumnId::tsid(), 1]
);
}
}
62 changes: 62 additions & 0 deletions tests/cases/standalone/common/create/create_metric_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,65 @@ DROP TABLE phy;

Affected Rows: 0

-- create one with other primary keys
CREATE TABLE phy2 (ts timestamp time index, val double, abc string, def string, primary key (abc, def)) engine=metric with ("physical_metric_table" = "");

Affected Rows: 0

DESC TABLE phy2;

+--------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------+----------------------+-----+------+---------+---------------+
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| val | Float64 | | YES | | FIELD |
| abc | String | PRI | YES | | TAG |
| def | String | PRI | YES | | TAG |
+--------+----------------------+-----+------+---------+---------------+

DROP TABLE phy2;

Affected Rows: 0

-- fuzz test case https://github.com/GreptimeTeam/greptimedb/issues/3612
CREATE TABLE `auT`(
incidunt TIMESTAMP(3) TIME INDEX,
`QuaErAT` BOOLEAN,
`REPREHenDERIt` BOOLEAN DEFAULT true,
`Et` INT NULL,
`AutEM` INT,
esse DOUBLE,
`Tempore` BOOLEAN,
`reruM` BOOLEAN,
`eRrOR` BOOLEAN NULL,
`cOMmodi` BOOLEAN,
`PERfERENdIS` DOUBLE,
`eSt` FLOAT DEFAULT 0.70978713,
PRIMARY KEY(`cOMmodi`, `PERfERENdIS`, esse)
) ENGINE = metric with ("physical_metric_table" = "");

Affected Rows: 0

DESC TABLE `auT`;

+---------------+----------------------+-----+------+------------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+---------------+----------------------+-----+------+------------+---------------+
| incidunt | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| QuaErAT | Boolean | | YES | | FIELD |
| REPREHenDERIt | Boolean | | YES | true | FIELD |
| Et | Int32 | | YES | | FIELD |
| AutEM | Int32 | | YES | | FIELD |
| esse | Float64 | PRI | YES | | TAG |
| Tempore | Boolean | | YES | | FIELD |
| reruM | Boolean | | YES | | FIELD |
| eRrOR | Boolean | | YES | | FIELD |
| cOMmodi | Boolean | PRI | YES | | TAG |
| PERfERENdIS | Float64 | PRI | YES | | TAG |
| eSt | Float32 | | YES | 0.70978713 | FIELD |
+---------------+----------------------+-----+------+------------+---------------+

DROP TABLE `auT`;

Affected Rows: 0

28 changes: 28 additions & 0 deletions tests/cases/standalone/common/create/create_metric_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,31 @@ DROP TABLE t1;
DROP TABLE t2;

DROP TABLE phy;

-- create one with other primary keys
CREATE TABLE phy2 (ts timestamp time index, val double, abc string, def string, primary key (abc, def)) engine=metric with ("physical_metric_table" = "");

DESC TABLE phy2;

DROP TABLE phy2;

-- fuzz test case https://github.com/GreptimeTeam/greptimedb/issues/3612
CREATE TABLE `auT`(
incidunt TIMESTAMP(3) TIME INDEX,
`QuaErAT` BOOLEAN,
`REPREHenDERIt` BOOLEAN DEFAULT true,
`Et` INT NULL,
`AutEM` INT,
esse DOUBLE,
`Tempore` BOOLEAN,
`reruM` BOOLEAN,
`eRrOR` BOOLEAN NULL,
`cOMmodi` BOOLEAN,
`PERfERENdIS` DOUBLE,
`eSt` FLOAT DEFAULT 0.70978713,
PRIMARY KEY(`cOMmodi`, `PERfERENdIS`, esse)
) ENGINE = metric with ("physical_metric_table" = "");

DESC TABLE `auT`;

DROP TABLE `auT`;

0 comments on commit b9890ab

Please sign in to comment.