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(query): tuple field name can not contain special char #15126

Merged
merged 2 commits into from
Mar 31, 2024
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: 12 additions & 4 deletions src/query/ast/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,15 +1611,23 @@ pub fn type_name(i: Input) -> IResult<TypeName> {
fields_type,
},
);
let ty_named_tuple = map(
let ty_named_tuple = map_res(
rule! { TUPLE ~ "(" ~ #comma_separated_list1(rule! { #ident ~ #type_name }) ~ ")" },
|(_, _, fields, _)| {
let (fields_name, fields_type) =
let (fields_name, fields_type): (Vec<String>, Vec<TypeName>) =
fields.into_iter().map(|(name, ty)| (name.name, ty)).unzip();
TypeName::Tuple {
if fields_name
.iter()
.any(|field_name| !field_name.chars().all(|c| c.is_ascii_alphanumeric()))
{
return Err(nom::Err::Error(ErrorKind::Other(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using failure:

Suggested change
return Err(nom::Err::Error(ErrorKind::Other(
return Err(nom::Err::Failure(ErrorKind::Other(

"Invalid tuple field name, only support alphanumeric characters",
)));
}
Ok(TypeName::Tuple {
fields_name: Some(fields_name),
fields_type,
}
})
},
);
let ty_date = value(TypeName::Date, rule! { DATE });
Expand Down
1 change: 1 addition & 0 deletions src/query/ast/tests/it/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ fn test_statement_error() {
r#"create table a (c tuple())"#,
r#"create table a (c decimal)"#,
r#"create table a (b tuple(c int, uint64));"#,
r#"create table a (b tuple("c-1" int, "c-2" uint64));"#,
r#"CREATE TABLE t(c1 NULLABLE(int) NOT NULL);"#,
r#"drop table if a.b"#,
r#"truncate table a.b.c.d"#,
Expand Down
15 changes: 15 additions & 0 deletions src/query/ast/tests/it/testdata/statement-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ error:
| while parsing `CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [<database>.]<table> [<source>] [<table_options>]`


---------- Input ----------
create table a (b tuple("c-1" int, "c-2" uint64));
---------- Output ---------
error:
--> SQL:1:48
|
1 | create table a (b tuple("c-1" int, "c-2" uint64));
| ------ - ----- ^ unexpected `)`, expecting `BOOLEAN`, `BOOL`, `UINT8`, `TINYINT`, `UINT16`, `SMALLINT`, `UINT32`, `INT`, `INTEGER`, `UINT64`, `UNSIGNED`, `BIGINT`, `INT8`, `INT16`, `INT32`, `INT64`, `SIGNED`, `FLOAT32`, `FLOAT`, `FLOAT64`, `DOUBLE`, `DECIMAL`, `ARRAY`, `MAP`, `BITMAP`, `TUPLE`, `DATE`, `DATETIME`, `TIMESTAMP`, `BINARY`, `VARBINARY`, `LONGBLOB`, `MEDIUMBLOB`, `TINYBLOB`, `BLOB`, `STRING`, `VARCHAR`, `CHAR`, `CHARACTER`, `TEXT`, `VARIANT`, `JSON`, `GEOMETRY`, `NULLABLE`, `(`, `NULL`, `NOT`, or `,`
| | | |
| | | while parsing TUPLE(<type>, ...)
| | | while parsing type name
| | while parsing `<column name> <type> [DEFAULT <expr>] [AS (<expr>) VIRTUAL] [AS (<expr>) STORED] [COMMENT '<comment>']`
| while parsing `CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [<database>.]<table> [<source>] [<table_options>]`


---------- Input ----------
CREATE TABLE t(c1 NULLABLE(int) NOT NULL);
---------- Output ---------
Expand Down
Loading