Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alter table procedure panics while renaming table #2397

Merged
merged 4 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/common/meta/src/ddl/alter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
})
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
))
}
Expand All @@ -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)),
}
}
9 changes: 5 additions & 4 deletions tests-integration/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions tests-integration/tests/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down Expand Up @@ -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,
Expand Down
Loading