Skip to content

Commit

Permalink
fix: support alter table ~ add ~ custom_type (#5165)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiwakaDev authored Dec 15, 2024
1 parent 579059d commit 358d5e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/sql/src/statements/transform/type_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
_ => {}
Expand Down
19 changes: 13 additions & 6 deletions tests/cases/standalone/common/alter/alter_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;

Expand Down
7 changes: 6 additions & 1 deletion tests/cases/standalone/common/alter/alter_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 358d5e1

Please sign in to comment.