mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-22 22:20:02 +00:00
fix: set is_time_index properly on updating physical table's schema (#3770)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)?;
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -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 |
|
||||
@@ -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 |
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 |
|
||||
@@ -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 |
|
||||
|
||||
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user