mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-08 06:12:55 +00:00
fix: alter table procedure panics while renaming table (#2397)
* fix: procedure panic on renaming table * test: fix test_insert_and_select invalid arguments * test: fix test_standalone_insert_and_query using wrong semantic type * test: fix test_distributed_insert_delete_and_query semantic type
This commit is contained in:
@@ -54,8 +54,8 @@ use crate::table_name::TableName;
|
||||
pub struct AlterTableProcedure {
|
||||
context: DdlContext,
|
||||
data: AlterTableData,
|
||||
/// proto alter Kind.
|
||||
kind: alter_request::Kind,
|
||||
/// proto alter Kind for adding/dropping columns.
|
||||
kind: Option<alter_request::Kind>,
|
||||
}
|
||||
|
||||
impl AlterTableProcedure {
|
||||
@@ -171,7 +171,7 @@ impl AlterTableProcedure {
|
||||
Ok(AlterRequest {
|
||||
region_id: region_id.as_u64(),
|
||||
schema_version: table_info.ident.version,
|
||||
kind: Some(self.kind.clone()),
|
||||
kind: self.kind.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ impl AlterTableData {
|
||||
pub fn create_proto_alter_kind(
|
||||
table_info: &RawTableInfo,
|
||||
alter_kind: &Kind,
|
||||
) -> Result<(alter_request::Kind, Option<ColumnId>)> {
|
||||
) -> Result<(Option<alter_request::Kind>, Option<ColumnId>)> {
|
||||
match alter_kind {
|
||||
Kind::AddColumns(x) => {
|
||||
let mut next_column_id = table_info.meta.next_column_id;
|
||||
@@ -494,7 +494,7 @@ pub fn create_proto_alter_kind(
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
Ok((
|
||||
alter_request::Kind::AddColumns(AddColumns { add_columns }),
|
||||
Some(alter_request::Kind::AddColumns(AddColumns { add_columns })),
|
||||
Some(next_column_id),
|
||||
))
|
||||
}
|
||||
@@ -508,10 +508,12 @@ pub fn create_proto_alter_kind(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok((
|
||||
alter_request::Kind::DropColumns(DropColumns { drop_columns }),
|
||||
Some(alter_request::Kind::DropColumns(DropColumns {
|
||||
drop_columns,
|
||||
})),
|
||||
None,
|
||||
))
|
||||
}
|
||||
Kind::RenameTable(_) => unreachable!(),
|
||||
Kind::RenameTable(_) => Ok((None, None)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,9 +195,10 @@ mod test {
|
||||
r"
|
||||
CREATE TABLE {table_name} (
|
||||
a INT,
|
||||
b STRING PRIMARY KEY,
|
||||
b STRING,
|
||||
ts TIMESTAMP,
|
||||
TIME INDEX (ts)
|
||||
TIME INDEX (ts),
|
||||
PRIMARY KEY (a, b)
|
||||
) PARTITION BY RANGE COLUMNS(a) (
|
||||
PARTITION r0 VALUES LESS THAN (10),
|
||||
PARTITION r1 VALUES LESS THAN (20),
|
||||
@@ -334,7 +335,7 @@ CREATE TABLE {table_name} (
|
||||
..Default::default()
|
||||
}),
|
||||
null_mask: vec![32, 0],
|
||||
semantic_type: SemanticType::Field as i32,
|
||||
semantic_type: SemanticType::Tag as i32,
|
||||
datatype: ColumnDataType::Int32 as i32,
|
||||
},
|
||||
Column {
|
||||
@@ -412,7 +413,7 @@ CREATE TABLE {table_name} (
|
||||
key_columns: vec![
|
||||
Column {
|
||||
column_name: "a".to_string(),
|
||||
semantic_type: SemanticType::Field as i32,
|
||||
semantic_type: SemanticType::Tag as i32,
|
||||
values: Some(Values {
|
||||
i32_values: a,
|
||||
..Default::default()
|
||||
|
||||
@@ -191,7 +191,7 @@ fn expect_data() -> (Column, Column, Column, Column) {
|
||||
.collect(),
|
||||
..Default::default()
|
||||
}),
|
||||
semantic_type: SemanticType::Field as i32,
|
||||
semantic_type: SemanticType::Tag as i32,
|
||||
datatype: ColumnDataType::String as i32,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -363,14 +363,14 @@ fn testing_create_expr() -> CreateTableExpr {
|
||||
ColumnDef {
|
||||
name: "ts".to_string(),
|
||||
data_type: ColumnDataType::TimestampMillisecond as i32, // timestamp
|
||||
is_nullable: true,
|
||||
is_nullable: false,
|
||||
default_constraint: vec![],
|
||||
semantic_type: SemanticType::Timestamp as i32,
|
||||
},
|
||||
];
|
||||
CreateTableExpr {
|
||||
catalog_name: "".to_string(),
|
||||
schema_name: "".to_string(),
|
||||
catalog_name: "greptime".to_string(),
|
||||
schema_name: "public".to_string(),
|
||||
table_name: "demo".to_string(),
|
||||
desc: "blabla little magic fairy".to_string(),
|
||||
column_defs,
|
||||
|
||||
Reference in New Issue
Block a user