-
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
Changes from 4 commits
6b7ac54
ef3da33
d26444d
93d9245
ea04755
3dca179
fe715d7
4638137
96e3164
f3a6cd8
6e25767
6947c15
7bf5b68
d898230
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ Cargo.lock | |
.vscode | ||
|
||
*.swp | ||
|
||
.DS_store |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,16 @@ use sqlparser::dialect::{BigQueryDialect, GenericDialect}; | |
use sqlparser::parser::{ParserError, ParserOptions}; | ||
use test_utils::*; | ||
|
||
#[test] | ||
fn test_struct() { | ||
// nested struct | ||
let canonical = r#"CREATE TABLE t1 (s STRUCT<v VARCHAR, s STRUCT<a1 INTEGER, a2 VARCHAR>>[])"#; | ||
let sql = r#"CREATE TABLE t1 (s STRUCT<v VARCHAR, s STRUCT<a1 INTEGER, a2 VARCHAR>>[])"#; | ||
let select = bigquery().parse_sql_statements(sql).unwrap().pop().unwrap(); | ||
// TODO: '>>' is incorrect parsed in bigquery syntax | ||
assert_ne!(select.to_string(), canonical); | ||
} | ||
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. not sure I follow if/why this test is needed, since bigquery doesn't support |
||
|
||
#[test] | ||
fn parse_literal_string() { | ||
let sql = concat!( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,39 @@ fn duckdb_and_generic() -> TestedDialects { | |
} | ||
} | ||
|
||
#[test] | ||
fn test_struct() { | ||
// basic struct | ||
let canonical = r#"CREATE TABLE t1 (s STRUCT<v VARCHAR, i INTEGER>)"#; | ||
let sql = r#"CREATE TABLE t1 (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. Oh I think this is incorrect, no need for the input and output to not match, in this case the output is significantly different syntax from what went into the parser. We can probably add a 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. It is not clear to me. Do you mean adding flag so we have different canonical name for 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. Ah yeah that's what I meant - my bad realised I wrote |
||
let select = duckdb().parse_sql_statements(sql).unwrap().pop().unwrap(); | ||
assert_eq!(select.to_string(), canonical); | ||
|
||
// struct array | ||
let canonical = r#"CREATE TABLE t1 (s STRUCT<v VARCHAR, i INTEGER>[])"#; | ||
let sql = r#"CREATE TABLE t1 (s STRUCT(v VARCHAR, i INTEGER)[])"#; | ||
let select = duckdb().parse_sql_statements(sql).unwrap().pop().unwrap(); | ||
assert_eq!(select.to_string(), canonical); | ||
|
||
// nested struct | ||
let canonical = r#"CREATE TABLE t1 (s STRUCT<v VARCHAR, s STRUCT<a1 INTEGER, a2 VARCHAR>>[])"#; | ||
let sql = r#"CREATE TABLE t1 (s STRUCT(v VARCHAR, s STRUCT(a1 INTEGER, a2 VARCHAR))[])"#; | ||
let select = duckdb().parse_sql_statements(sql).unwrap().pop().unwrap(); | ||
assert_eq!(select.to_string(), canonical); | ||
|
||
// failing test | ||
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 )"#, | ||
]; | ||
|
||
for sql in sql_list { | ||
duckdb().parse_sql_statements(sql).unwrap_err(); | ||
} | ||
} | ||
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"); | ||
|
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.
There's a slight mismatch I'm thinking might not be worth having - the open delimeter token is configurable now but here the function still needs to figure out for itself what the value is for the closing token.
The function is a bit complicated on its own, specifically due to the
<
delimeter. then since duckdb syntax doesn't have that I'm thinking it makes sense to use a dedicated function that is simpler.Something roughly like this I think should be all duckdb need, would it make sense to add this instead and have duckdb (and any future dialect sharing the same syntax) use it?
This comment was marked as outdated.
Sorry, something went wrong.