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

feat(query): modify alter table column parser #14282

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,7 @@ pub fn alter_table_action(i: Input) -> IResult<AlterTableAction> {
);
let rename_column = map(
rule! {
RENAME ~ COLUMN ~ #ident ~ TO ~ #ident
RENAME ~ COLUMN? ~ #ident ~ TO ~ #ident
},
|(_, _, old_column, _, new_column)| AlterTableAction::RenameColumn {
old_column,
Expand All @@ -2672,7 +2672,7 @@ pub fn alter_table_action(i: Input) -> IResult<AlterTableAction> {
);
let add_column = map(
rule! {
ADD ~ COLUMN ~ #column_def ~ ( #add_column_option )?
ADD ~ COLUMN? ~ #column_def ~ ( #add_column_option )?
},
|(_, _, column, option)| AlterTableAction::AddColumn {
column,
Expand All @@ -2682,14 +2682,14 @@ pub fn alter_table_action(i: Input) -> IResult<AlterTableAction> {

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 },
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

Expand Down
Loading