From bb5dfc327fd3921128025c2f42a0618f2a45663e Mon Sep 17 00:00:00 2001 From: Kould Date: Tue, 9 Jan 2024 18:40:23 +0000 Subject: [PATCH] feat(parser): modify alter table column parser --- src/query/ast/src/parser/statement.rs | 8 +-- ...5_0003_ddl_create_add_computed_column.test | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/query/ast/src/parser/statement.rs b/src/query/ast/src/parser/statement.rs index 1267a1f00fc2..5d8af7f4c2d0 100644 --- a/src/query/ast/src/parser/statement.rs +++ b/src/query/ast/src/parser/statement.rs @@ -2663,7 +2663,7 @@ pub fn alter_table_action(i: Input) -> IResult { ); let rename_column = map( rule! { - RENAME ~ COLUMN ~ #ident ~ TO ~ #ident + RENAME ~ COLUMN? ~ #ident ~ TO ~ #ident }, |(_, _, old_column, _, new_column)| AlterTableAction::RenameColumn { old_column, @@ -2672,7 +2672,7 @@ pub fn alter_table_action(i: Input) -> IResult { ); let add_column = map( rule! { - ADD ~ COLUMN ~ #column_def ~ ( #add_column_option )? + ADD ~ COLUMN? ~ #column_def ~ ( #add_column_option )? }, |(_, _, column, option)| AlterTableAction::AddColumn { column, @@ -2682,14 +2682,14 @@ pub fn alter_table_action(i: Input) -> IResult { let modify_column = map( rule! { - MODIFY ~ COLUMN ~ #modify_column_action + MODIFY ~ COLUMN? ~ #modify_column_action }, |(_, _, action)| AlterTableAction::ModifyColumn { action }, ); let drop_column = map( rule! { - DROP ~ COLUMN ~ #ident + DROP ~ COLUMN? ~ #ident }, |(_, _, column)| AlterTableAction::DropColumn { column }, ); diff --git a/tests/sqllogictests/suites/ee/05_ee_ddl/05_0003_ddl_create_add_computed_column.test b/tests/sqllogictests/suites/ee/05_ee_ddl/05_0003_ddl_create_add_computed_column.test index 015e8df33043..bf87b13cccf9 100644 --- a/tests/sqllogictests/suites/ee/05_ee_ddl/05_0003_ddl_create_add_computed_column.test +++ b/tests/sqllogictests/suites/ee/05_ee_ddl/05_0003_ddl_create_add_computed_column.test @@ -48,6 +48,36 @@ alter table t1 rename column a to x statement ok alter table t1 drop column x +statement ok +drop table t1 + +statement ok +create table t1(a string null default 'a', b string null as (concat(a, '-', c)) stored, c string null default 'c', d string null as (reverse(a)) virtual) + +statement ok +alter table t1 add f string null as (lower(c)) virtual + +statement error 1065 +alter table t1 add e string null as (upper(c)) stored + +statement ok +alter table t1 drop b + +statement error 1117 +alter table t1 rename a to x + +statement error 1117 +alter table t1 drop a + +statement ok +alter table t1 drop d + +statement ok +alter table t1 rename a to x + +statement ok +alter table t1 drop x + statement ok create table t2(a string, b string generated always as (upper(a)) stored, c string generated always as (lower(a)) virtual) @@ -57,12 +87,33 @@ alter table t2 modify column c drop stored statement ok alter table t2 modify column b drop stored +statement ok +drop table t2 + +statement ok +create table t2(a string, b string generated always as (upper(a)) stored, c string generated always as (lower(a)) virtual) + +statement error 1058 +alter table t2 modify c drop stored + +statement ok +alter table t2 modify b drop stored + statement ok create table t3(a string, b string as (concat(a, '-')) stored) statement error 1117 alter table t3 modify column a float +statement ok +drop table t3 + +statement ok +create table t3(a string, b string as (concat(a, '-')) stored) + +statement error 1117 +alter table t3 modify a float + statement ok USE default