From 358d5e1d63cc28cee30fe3b213fef26f5fb71aac Mon Sep 17 00:00:00 2001 From: Niwaka <61189782+NiwakaDev@users.noreply.github.com> Date: Sun, 15 Dec 2024 18:05:29 +0900 Subject: [PATCH] fix: support alter table ~ add ~ custom_type (#5165) --- .../src/statements/transform/type_alias.rs | 4 ++++ .../common/alter/alter_table.result | 19 +++++++++++++------ .../standalone/common/alter/alter_table.sql | 7 ++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/sql/src/statements/transform/type_alias.rs b/src/sql/src/statements/transform/type_alias.rs index 9e51ca918041..d670a63b47ed 100644 --- a/src/sql/src/statements/transform/type_alias.rs +++ b/src/sql/src/statements/transform/type_alias.rs @@ -57,6 +57,10 @@ impl TransformRule for TypeAliasTransformRule { alter_table.alter_operation_mut() { replace_type_alias(target_type) + } else if let AlterTableOperation::AddColumn { column_def, .. } = + alter_table.alter_operation_mut() + { + replace_type_alias(&mut column_def.data_type); } } _ => {} diff --git a/tests/cases/standalone/common/alter/alter_table.result b/tests/cases/standalone/common/alter/alter_table.result index 120e7695d03f..5c1dbfca77a8 100644 --- a/tests/cases/standalone/common/alter/alter_table.result +++ b/tests/cases/standalone/common/alter/alter_table.result @@ -140,10 +140,17 @@ ADD Affected Rows: 0 +ALTER TABLE + t2 +ADD + COLUMN at4 UINT16; + +Affected Rows: 0 + INSERT INTO t2 VALUES - ("loc_1", "loc_2", "loc_3", 'job1', 0, 1); + ("loc_1", "loc_2", "loc_3", 2, 'job1', 0, 1); Affected Rows: 1 @@ -152,11 +159,11 @@ SELECT FROM t2; -+-------+-------+-------+------+---------------------+-----+ -| at | at2 | at3 | job | ts | val | -+-------+-------+-------+------+---------------------+-----+ -| loc_1 | loc_2 | loc_3 | job1 | 1970-01-01T00:00:00 | 1.0 | -+-------+-------+-------+------+---------------------+-----+ ++-------+-------+-------+-----+------+---------------------+-----+ +| at | at2 | at3 | at4 | job | ts | val | ++-------+-------+-------+-----+------+---------------------+-----+ +| loc_1 | loc_2 | loc_3 | 2 | job1 | 1970-01-01T00:00:00 | 1.0 | ++-------+-------+-------+-----+------+---------------------+-----+ DROP TABLE t1; diff --git a/tests/cases/standalone/common/alter/alter_table.sql b/tests/cases/standalone/common/alter/alter_table.sql index 7f3e0b664038..c52a2445db42 100644 --- a/tests/cases/standalone/common/alter/alter_table.sql +++ b/tests/cases/standalone/common/alter/alter_table.sql @@ -67,10 +67,15 @@ ALTER TABLE ADD COLUMN at2 STRING; +ALTER TABLE + t2 +ADD + COLUMN at4 UINT16; + INSERT INTO t2 VALUES - ("loc_1", "loc_2", "loc_3", 'job1', 0, 1); + ("loc_1", "loc_2", "loc_3", 2, 'job1', 0, 1); SELECT *