iffyio commented on code in PR #2385:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2385#discussion_r3445528794
##########
src/parser/mod.rs:
##########
@@ -4392,6 +4392,17 @@ impl<'a> Parser<'a> {
negated,
});
}
+ // ClickHouse accepts a bare expression as the IN RHS (e.g. `x IN 'a'`
or
+ // a `{name:Type}` placeholder), wrapping it into a single-element
list.
Review Comment:
```suggestion
```
##########
tests/sqlparser_clickhouse.rs:
##########
@@ -1846,6 +1846,44 @@ fn parse_inner_array_join() {
}
}
+#[test]
+fn parse_in_unparenthesized_placeholder() {
+ // ClickHouse `{name:Type}` query-parameter placeholder as the IN RHS,
without parens.
+ match clickhouse().expr_parses_to("x IN {ids:Array(UInt64)}", "x IN ({ids:
Array(UInt64)})") {
Review Comment:
lets rewrite these tests to use all_dialects_where and verified_stmt, we can
remove the test for dialects that donts support the feature
##########
src/dialect/clickhouse.rs:
##########
@@ -80,6 +80,10 @@ impl Dialect for ClickHouseDialect {
true
}
+ fn supports_in_unparenthesized_expr(&self) -> bool {
Review Comment:
lets add a link to the docs where the syntax comes from
##########
tests/sqlparser_clickhouse.rs:
##########
@@ -1846,6 +1846,44 @@ fn parse_inner_array_join() {
}
}
+#[test]
+fn parse_in_unparenthesized_placeholder() {
+ // ClickHouse `{name:Type}` query-parameter placeholder as the IN RHS,
without parens.
+ match clickhouse().expr_parses_to("x IN {ids:Array(UInt64)}", "x IN ({ids:
Array(UInt64)})") {
+ Expr::InList { list, negated, .. } => {
+ assert!(!negated);
+ assert_eq!(list.len(), 1);
+ assert!(matches!(list[0], Expr::Dictionary(_)));
+ }
+ other => panic!("expected InList, got {other:?}"),
Review Comment:
we can probably drop the ast assertions, I think the funcationality is
simple enough to rely only on roundtrip tests
##########
src/dialect/mod.rs:
##########
@@ -435,6 +435,15 @@ pub trait Dialect: Debug + Any {
false
}
+ /// Returns true if the dialect supports a bare expression as the
right-hand
+ /// side of `IN`, without a parenthesized list — as in `x IN 'a'` or the
+ /// ClickHouse `{name:Type}` query-parameter placeholder `x IN
{ids:Array(UInt64)}`.
+ /// The expression is wrapped into a single-element list, matching
ClickHouse,
+ /// which reformats `x IN 'a'` to `x IN ('a')`.
Review Comment:
```suggestion
/// side of `IN`, without a parenthesized list — as in `x IN 'a'`.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]