Skip to content

Commit

Permalink
fix: set is_time_index properly on updating physical table's schema (#…
Browse files Browse the repository at this point in the history
…3770)

Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Apr 22, 2024
1 parent 9e1441e commit bf21527
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/common/meta/src/ddl/physical_table_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ pub(crate) fn build_new_physical_table_info(
columns.push(col.column_schema.clone());
}

if let Some(time_index) = *time_index {
raw_table_info.meta.schema.column_schemas[time_index].set_time_index();
}

raw_table_info
}
12 changes: 12 additions & 0 deletions src/datatypes/src/schema/column_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl fmt::Debug for ColumnSchema {
if self.is_nullable { "null" } else { "not null" },
)?;

if self.is_time_index {
write!(f, " time_index")?;
}

// Add default constraint if present
if let Some(default_constraint) = &self.default_constraint {
write!(f, " default={:?}", default_constraint)?;
Expand Down Expand Up @@ -159,6 +163,14 @@ impl ColumnSchema {
self.is_nullable = true;
}

/// Set the `is_time_index` to `true` of the column.
/// Similar to [with_time_index] but don't take the ownership.
///
/// [with_time_index]: Self::with_time_index
pub fn set_time_index(&mut self) {
self.is_time_index = true;
}

/// Creates a new [`ColumnSchema`] with given metadata.
pub fn with_metadata(mut self, metadata: Metadata) -> Self {
self.metadata = metadata;
Expand Down
13 changes: 11 additions & 2 deletions tests/cases/standalone/common/alter/alter_metric_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ SHOW TABLES;
| phy |
+---------+

DESC TABLE phy;

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

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

Affected Rows: 0
Expand Down Expand Up @@ -44,7 +53,7 @@ DESC TABLE phy;
+------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+------------+----------------------+-----+------+---------+---------------+
| ts | TimestampMillisecond | | NO | | FIELD |
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| val | Float64 | | YES | | FIELD |
| __table_id | UInt32 | PRI | NO | | TAG |
| __tsid | UInt64 | PRI | NO | | TAG |
Expand Down Expand Up @@ -87,7 +96,7 @@ DESC TABLE phy;
+------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+------------+----------------------+-----+------+---------+---------------+
| ts | TimestampMillisecond | | NO | | FIELD |
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| val | Float64 | | YES | | FIELD |
| __table_id | UInt32 | PRI | NO | | TAG |
| __tsid | UInt64 | PRI | NO | | TAG |
Expand Down
2 changes: 2 additions & 0 deletions tests/cases/standalone/common/alter/alter_metric_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ CREATE TABLE phy (ts timestamp time index, val double) engine=metric with ("phys

SHOW TABLES;

DESC TABLE phy;

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

CREATE TABLE t2 (ts timestamp time index, job string primary key, val double) engine = metric with ("on_physical_table" = "phy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ DESC TABLE phy;
+------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+------------+----------------------+-----+------+---------+---------------+
| ts | TimestampMillisecond | | NO | | FIELD |
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| val | Float64 | | YES | | FIELD |
| __table_id | UInt32 | PRI | NO | | TAG |
| __tsid | UInt64 | PRI | NO | | TAG |
Expand Down Expand Up @@ -83,7 +83,7 @@ DESC TABLE phy;
+------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+------------+----------------------+-----+------+---------+---------------+
| ts | TimestampMillisecond | | NO | | FIELD |
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| val | Float64 | | YES | | FIELD |
| __table_id | UInt32 | PRI | NO | | TAG |
| __tsid | UInt64 | PRI | NO | | TAG |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DESC TABLE phy;
+------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+------------+----------------------+-----+------+---------+---------------+
| ts | TimestampMillisecond | | NO | | FIELD |
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
| val | Float64 | | YES | | FIELD |
| __table_id | UInt32 | PRI | NO | | TAG |
| __tsid | UInt64 | PRI | NO | | TAG |
Expand Down

0 comments on commit bf21527

Please sign in to comment.