-
Notifications
You must be signed in to change notification settings - Fork 736
ClickHouse: Support unparenthesized IN right-hand side #2385
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2375,15 +2375,45 @@ fn parse_in_unnest() { | |
|
|
||
| #[test] | ||
| fn parse_in_error() { | ||
| // <expr> IN <expr> is no valid | ||
| // <expr> IN <expr> is no valid, except in dialects that accept an | ||
| // unparenthesized expression as the IN right-hand side (e.g. ClickHouse). | ||
| let sql = "SELECT * FROM customers WHERE segment in segment"; | ||
| let res = parse_sql_statements(sql); | ||
| let res = | ||
| all_dialects_except(|d| d.supports_in_unparenthesized_expr()).parse_sql_statements(sql); | ||
| assert_eq!( | ||
| ParserError::ParserError("Expected: (, found: segment".to_string()), | ||
| res.unwrap_err() | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_in_unparenthesized_expr() { | ||
| // Dialects supporting an unparenthesized IN right-hand side wrap a bare expression | ||
| // into a single-element list (e.g. `x IN 'a'` -> `x IN ('a')`). | ||
| let dialects = all_dialects_where(|d| d.supports_in_unparenthesized_expr()); | ||
| dialects.expr_parses_to("x IN 'a'", "x IN ('a')"); | ||
|
|
||
| // The branch must not fire when the next token is `(` (regressions). | ||
| dialects.verified_expr("x IN (1, 2, 3)"); | ||
| dialects.verified_stmt("SELECT * FROM t WHERE x IN (SELECT y FROM u)"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_in_unparenthesized_dictionary_placeholder() { | ||
| // The `{name:Type}` placeholder form additionally requires dictionary syntax. | ||
| let dialects = all_dialects_where(|d| { | ||
| d.supports_in_unparenthesized_expr() && d.supports_dictionary_syntax() | ||
| }); | ||
| dialects.expr_parses_to("x IN {ids:Array(UInt64)}", "x IN ({ids: Array(UInt64)})"); | ||
| dialects.expr_parses_to( | ||
| "x NOT IN {ids:Array(UInt64)}", | ||
| "x NOT IN ({ids: Array(UInt64)})", | ||
| ); | ||
| dialects.verified_expr("x IN ({ids: Array(UInt64)})"); | ||
| // Precedence: the trailing `AND` is not swallowed. | ||
| dialects.verified_expr("x IN ({p: Array(UInt64)}) AND y = 1"); | ||
| } | ||
|
Comment on lines
+2400
to
+2415
Contributor
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. is there some special handling for dictionaries we're accounting for? if not I think this test we can probably remove |
||
|
|
||
| #[test] | ||
| fn parse_string_agg() { | ||
| let sql = "SELECT a || b"; | ||
|
|
@@ -10834,8 +10864,11 @@ fn parse_position() { | |
|
|
||
| #[test] | ||
| fn parse_position_negative() { | ||
| // Dialects that accept an unparenthesized IN right-hand side (e.g. ClickHouse) | ||
| // report a different error here, so exclude them. | ||
| let sql = "SELECT POSITION(foo IN) from bar"; | ||
| let res = parse_sql_statements(sql); | ||
| let res = | ||
| all_dialects_except(|d| d.supports_in_unparenthesized_expr()).parse_sql_statements(sql); | ||
| assert_eq!( | ||
| ParserError::ParserError("Expected: (, found: )".to_string()), | ||
|
Comment on lines
+10867
to
10873
Contributor
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. maybe we can also add a similar assertion for dialects that do support unparenthesized IN? |
||
| res.unwrap_err() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.