You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/07/01 09:15:28 UTC
(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2385-a023b78f6908dd19436492850cfc66b083ba5b91 created (now b478611b)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-2385-a023b78f6908dd19436492850cfc66b083ba5b91
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
at b478611b ClickHouse: Support unparenthesized IN right-hand side (#2385)
This branch includes the following new commits:
new b478611b ClickHouse: Support unparenthesized IN right-hand side (#2385)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion-sqlparser-rs) 01/01: ClickHouse: Support unparenthesized IN right-hand side (#2385)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-2385-a023b78f6908dd19436492850cfc66b083ba5b91
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit b478611b16b7d17128ec32d9108cf83ca8819d5d
Author: Dinmukhamed Mailibay <47...@users.noreply.github.com>
AuthorDate: Wed Jul 1 10:15:03 2026 +0100
ClickHouse: Support unparenthesized IN right-hand side (#2385)
---
src/dialect/clickhouse.rs | 5 +++++
src/dialect/mod.rs | 10 ++++++++++
src/parser/mod.rs | 9 +++++++++
tests/sqlparser_clickhouse.rs | 23 +++++++++++++++++++++++
tests/sqlparser_common.rs | 31 ++++++++++++++++++++++++++++---
5 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/src/dialect/clickhouse.rs b/src/dialect/clickhouse.rs
index 6ee60cc9..9061036f 100644
--- a/src/dialect/clickhouse.rs
+++ b/src/dialect/clickhouse.rs
@@ -80,6 +80,11 @@ impl Dialect for ClickHouseDialect {
true
}
+ // See <https://clickhouse.com/docs/sql-reference/operators/in>
+ fn supports_in_unparenthesized_expr(&self) -> bool {
+ true
+ }
+
/// See <https://clickhouse.com/docs/en/sql-reference/functions#higher-order-functions---operator-and-lambdaparams-expr-function>
fn supports_lambda_functions(&self) -> bool {
true
diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs
index f7caa756..efabfeb1 100644
--- a/src/dialect/mod.rs
+++ b/src/dialect/mod.rs
@@ -447,6 +447,12 @@ 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'`.
+ fn supports_in_unparenthesized_expr(&self) -> bool {
+ false
+ }
+
/// Returns true if the dialect supports `BEGIN {DEFERRED | IMMEDIATE | EXCLUSIVE | TRY | CATCH} [TRANSACTION]` statements
fn supports_start_transaction_modifier(&self) -> bool {
false
@@ -2063,6 +2069,10 @@ mod tests {
self.0.supports_in_empty_list()
}
+ fn supports_in_unparenthesized_expr(&self) -> bool {
+ self.0.supports_in_unparenthesized_expr()
+ }
+
fn convert_type_before_value(&self) -> bool {
self.0.convert_type_before_value()
}
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index d2fa9071..1e0c5fbb 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -4392,6 +4392,15 @@ impl<'a> Parser<'a> {
negated,
});
}
+ if self.dialect.supports_in_unparenthesized_expr()
+ && self.peek_token_ref().token != Token::LParen
+ {
+ return Ok(Expr::InList {
+ expr: Box::new(expr),
+ list: vec![self.parse_expr()?],
+ negated,
+ });
+ }
self.expect_token(&Token::LParen)?;
let in_op = match self.maybe_parse(|p| p.parse_query())? {
Some(subquery) => Expr::InSubquery {
diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs
index cb2df1ff..258f4436 100644
--- a/tests/sqlparser_clickhouse.rs
+++ b/tests/sqlparser_clickhouse.rs
@@ -1846,6 +1846,29 @@ fn parse_inner_array_join() {
}
}
+#[test]
+fn parse_in_unparenthesized_expr() {
+ // IN [expr] parses to IN ([expr]) and does not cause regressions
+ clickhouse().expr_parses_to("x IN 'a'", "x IN ('a')");
+
+ // The branch must not fire when the next token is `(` (regressions).
+ clickhouse().verified_expr("x IN (1, 2, 3)");
+ clickhouse().verified_stmt("SELECT * FROM t WHERE x IN (SELECT y FROM u)");
+}
+
+#[test]
+fn parse_in_unparenthesized_dictionary_placeholder() {
+ // IN [{placeholder:Type}] parses to IN ({placholder:Type})
+ clickhouse().expr_parses_to("x IN {ids:Array(UInt64)}", "x IN ({ids: Array(UInt64)})");
+ clickhouse().expr_parses_to(
+ "x NOT IN {ids:Array(UInt64)}",
+ "x NOT IN ({ids: Array(UInt64)})",
+ );
+ clickhouse().verified_expr("x IN ({ids: Array(UInt64)})");
+ // Precedence: the trailing `AND` is not swallowed.
+ clickhouse().verified_expr("x IN ({p: Array(UInt64)}) AND y = 1");
+}
+
fn clickhouse() -> TestedDialects {
TestedDialects::new(vec![Box::new(ClickHouseDialect {})])
}
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 2af90809..cfc04e9b 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -2383,15 +2383,29 @@ 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_string_agg() {
let sql = "SELECT a || b";
@@ -10842,12 +10856,23 @@ 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()),
res.unwrap_err()
);
+
+ let result_unparenthesized =
+ all_dialects_where(|d| d.supports_in_unparenthesized_expr()).parse_sql_statements(sql);
+
+ assert_eq!(
+ ParserError::ParserError("Expected: an expression, found: )".to_string()),
+ result_unparenthesized.unwrap_err()
+ );
}
#[test]
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org