LucaCappelletti94 commented on code in PR #2598:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2598#discussion_r4173568543


##########
src/parser/mod.rs:
##########
@@ -4468,6 +4478,7 @@ impl<'a> Parser<'a> {
                 expr: Box::new(expr),
                 list: vec![self.parse_expr()?],

Review Comment:
   ClickHouse groups `x GLOBAL IN t2 AND y = 2` as `(x GLOBAL IN t2) AND y = 
2`, but this path renders `x GLOBAL IN (t2 AND y = 2)`.
   
   ```suggestion
                   list: 
vec![self.parse_subexpr(self.dialect.prec_value(Precedence::Eq))?],
   ```



##########
tests/sqlparser_clickhouse.rs:
##########
@@ -2084,6 +2084,60 @@ fn parse_tuple_element_access() {
     }
 }
 
+#[test]
+fn parse_global_in() {
+    let select = clickhouse().verified_only_select("SELECT * FROM t WHERE x 
GLOBAL IN (1, 2)");
+    assert_eq!(
+        select.selection.unwrap(),
+        Expr::InList {
+            expr: Box::new(Identifier(Ident::new("x"))),
+            list: vec![
+                Expr::Value(number("1").with_empty_span()),
+                Expr::Value(number("2").with_empty_span()),
+            ],
+            negated: false,
+            global: true,
+        }
+    );
+
+    let select = clickhouse()
+        .verified_only_select("SELECT * FROM t WHERE x GLOBAL NOT IN (SELECT y 
FROM t2)");
+    assert_eq!(
+        select.selection.unwrap(),
+        Expr::InSubquery {
+            expr: Box::new(Identifier(Ident::new("x"))),
+            subquery: Box::new(clickhouse().verified_query("SELECT y FROM 
t2")),
+            negated: true,
+            global: true,
+        }
+    );
+
+    clickhouse().one_statement_parses_to(
+        "SELECT * FROM t WHERE x GLOBAL IN t2",
+        "SELECT * FROM t WHERE x GLOBAL IN (t2)",
+    );
+
+    let select =
+        clickhouse().verified_only_select("SELECT * FROM t WHERE x GLOBAL IN 
(1) AND y = 2");
+    assert!(matches!(
+        select.selection.unwrap(),
+        BinaryOp {
+            op: BinaryOperator::And,
+            ..
+        }
+    ));
+
+    assert!(clickhouse()
+        .parse_sql_statements("SELECT * FROM t WHERE x GLOBAL y")
+        .is_err());
+
+    for dialect in all_dialects_where(|d| !d.supports_global_in()).dialects {
+        assert!(TestedDialects::new(vec![dialect])
+            .parse_sql_statements("SELECT * FROM t WHERE x GLOBAL IN (1)")
+            .is_err());
+    }
+}

Review Comment:
   Some red tests
   
   ```suggestion
   }
   
   #[test]
   fn global_in_bare_table_binds_before_and() {
       let expr =
           clickhouse().expr_parses_to("x GLOBAL IN t2 AND y = 2", "x GLOBAL IN 
(t2) AND y = 2");
       assert!(matches!(
           expr,
           BinaryOp {
               left,
               op: BinaryOperator::And,
               ..
           } if matches!(*left, Expr::InList { global: true, .. })
       ));
   }
   
   #[test]
   fn global_in_bare_table_binds_before_equality() {
       let expr = clickhouse().expr_parses_to("x GLOBAL IN t2 = 1", "x GLOBAL 
IN (t2) = 1");
       assert!(matches!(
           expr,
           BinaryOp {
               left,
               op: BinaryOperator::Eq,
               ..
           } if matches!(*left, Expr::InList { global: true, .. })
       ));
   }
   ```



-- 
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]

Reply via email to