mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 03:07:20 +00:00
Don't fail parsing a column definition with unexpected tokens
Since PR https://github.com/ballista-compute/sqlparser-rs/pull/93 `parse_column_def` parses a set of column options in a loop, e.g. given: ``` _______ column_def _______ CREATE TABLE foo (bar INT NOT NULL DEFAULT 1, ) -------- --------- option 1 option 2 ```` it parses column options until it encounters one of the delimiter tokens First when we only supported `CREATE TABLE`, the set of delimiters that stopped the parsing used to be `Token::Comma | Token::RParen`. Then we added support for `ALTER TABLE ADD COLUMN <column_def>`. Turns out the parser started to bail if the statement ended with a semicolon, while attempting to parse the semicolon as a column option, as we forgot to add it to the set of delimiter tokens. This was recently fixed in https://github.com/ballista-compute/sqlparser-rs/pull/246 by including Token::SemiColon to the list, but it felt wrong to have to update this list, and to have a common list of delimiters for two different contexts (CREATE TABLE with parens vs ALTER TABLE ADD COLUMN without parens). Also our current approach cannot handle multiple statements NOT separated by a semicolon, as is common in MS SQL DDL. We don't explicitly support it in `parse_statements`, but that's a use-case like to keep in mind nevertheless.
This commit is contained in:
parent
23f5c7e7ce
commit
66505ebf9e
2 changed files with 40 additions and 27 deletions
|
@ -1142,7 +1142,13 @@ fn parse_create_table() {
|
|||
assert!(res
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Expected column option, found: GARBAGE"));
|
||||
.contains("Expected \',\' or \')\' after column definition, found: GARBAGE"));
|
||||
|
||||
let res = parse_sql_statements("CREATE TABLE t (a int NOT NULL CONSTRAINT foo)");
|
||||
assert!(res
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Expected constraint details after CONSTRAINT <name>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue