-
Notifications
You must be signed in to change notification settings - Fork 534
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
Support DuckDB struct syntax and support list of struct syntax #1372
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6b7ac54
enable duckdb struct
jayzhan211 ef3da33
fmt
jayzhan211 d26444d
add test
jayzhan211 93d9245
add failing test and simplify code
jayzhan211 ea04755
simplifed duckdb struct parser
jayzhan211 3dca179
simplified old func
jayzhan211 fe715d7
bracket kind
jayzhan211 4638137
rename
jayzhan211 96e3164
add more test and return error
jayzhan211 f3a6cd8
Update tests/sqlparser_duckdb.rs
alamb 6e25767
Add docs for `StructBrackedKind`
alamb 6947c15
Merge branch 'duckdb-struct' of github.com:jayzhan211/sqlparser-rs in…
alamb 7bf5b68
Merge remote-tracking branch 'origin/main' into duckdb-struct
alamb d898230
Improve tests
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ Cargo.lock | |
.vscode | ||
|
||
*.swp | ||
|
||
.DS_store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,118 @@ fn duckdb_and_generic() -> TestedDialects { | |
} | ||
} | ||
|
||
#[test] | ||
fn test_struct() { | ||
// s STRUCT(v VARCHAR, i INTEGER) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the tests to also have coverage of the actual parsed data types |
||
let struct_type1 = DataType::Struct( | ||
vec![ | ||
StructField { | ||
field_name: Some(Ident::new("v")), | ||
field_type: DataType::Varchar(None), | ||
}, | ||
StructField { | ||
field_name: Some(Ident::new("i")), | ||
field_type: DataType::Integer(None), | ||
}, | ||
], | ||
StructBracketKind::Parentheses, | ||
); | ||
|
||
// basic struct | ||
let statement = duckdb().verified_stmt(r#"CREATE TABLE t1 (s STRUCT(v VARCHAR, i INTEGER))"#); | ||
assert_eq!( | ||
column_defs(statement), | ||
vec![ColumnDef { | ||
name: "s".into(), | ||
data_type: struct_type1.clone(), | ||
collation: None, | ||
options: vec![], | ||
}] | ||
); | ||
|
||
// struct array | ||
let statement = duckdb().verified_stmt(r#"CREATE TABLE t1 (s STRUCT(v VARCHAR, i INTEGER)[])"#); | ||
assert_eq!( | ||
column_defs(statement), | ||
vec![ColumnDef { | ||
name: "s".into(), | ||
data_type: DataType::Array(ArrayElemTypeDef::SquareBracket( | ||
Box::new(struct_type1), | ||
None | ||
)), | ||
collation: None, | ||
options: vec![], | ||
}] | ||
); | ||
|
||
// s STRUCT(v VARCHAR, s STRUCT(a1 INTEGER, a2 VARCHAR)) | ||
let struct_type2 = DataType::Struct( | ||
vec![ | ||
StructField { | ||
field_name: Some(Ident::new("v")), | ||
field_type: DataType::Varchar(None), | ||
}, | ||
StructField { | ||
field_name: Some(Ident::new("s")), | ||
field_type: DataType::Struct( | ||
vec![ | ||
StructField { | ||
field_name: Some(Ident::new("a1")), | ||
field_type: DataType::Integer(None), | ||
}, | ||
StructField { | ||
field_name: Some(Ident::new("a2")), | ||
field_type: DataType::Varchar(None), | ||
}, | ||
], | ||
StructBracketKind::Parentheses, | ||
), | ||
}, | ||
], | ||
StructBracketKind::Parentheses, | ||
); | ||
|
||
// nested struct | ||
let statement = duckdb().verified_stmt( | ||
r#"CREATE TABLE t1 (s STRUCT(v VARCHAR, s STRUCT(a1 INTEGER, a2 VARCHAR))[])"#, | ||
); | ||
|
||
assert_eq!( | ||
column_defs(statement), | ||
vec![ColumnDef { | ||
name: "s".into(), | ||
data_type: DataType::Array(ArrayElemTypeDef::SquareBracket( | ||
Box::new(struct_type2), | ||
None | ||
)), | ||
collation: None, | ||
options: vec![], | ||
}] | ||
); | ||
|
||
// failing test (duckdb does not support bracket syntax) | ||
let sql_list = vec![ | ||
r#"CREATE TABLE t1 (s STRUCT(v VARCHAR, i INTEGER)))"#, | ||
jayzhan211 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
r#"CREATE TABLE t1 (s STRUCT(v VARCHAR, i INTEGER>)"#, | ||
r#"CREATE TABLE t1 (s STRUCT<v VARCHAR, i INTEGER>)"#, | ||
r#"CREATE TABLE t1 (s STRUCT v VARCHAR, i INTEGER )"#, | ||
r#"CREATE TABLE t1 (s STRUCT VARCHAR, i INTEGER )"#, | ||
r#"CREATE TABLE t1 (s STRUCT (VARCHAR, INTEGER))"#, | ||
]; | ||
|
||
for sql in sql_list { | ||
duckdb().parse_sql_statements(sql).unwrap_err(); | ||
} | ||
} | ||
|
||
/// Returns the ColumnDefinitions from a CreateTable statement | ||
fn column_defs(statement: Statement) -> Vec<ColumnDef> { | ||
match statement { | ||
Statement::CreateTable(CreateTable { columns, .. }) => columns, | ||
_ => panic!("Expected CreateTable"), | ||
} | ||
} | ||
jayzhan211 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#[test] | ||
fn test_select_wildcard_with_exclude() { | ||
let select = duckdb().verified_only_select("SELECT * EXCLUDE (col_a) FROM data"); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added some comments on this struct