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/08/04 09:24:28 UTC

(datafusion-sqlparser-rs) 01/01: Honour operator precedence in SQLite `REGEXP`, `MATCH` and `GLOB` (#2419)

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-2419-2f3b5b824c24304720f1e8e504f54b9910e63bad
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit c4e7dc5c49e830dba172d23381061c602d8dfcdc
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Tue Aug 4 11:24:06 2026 +0200

    Honour operator precedence in SQLite `REGEXP`, `MATCH` and `GLOB` (#2419)
---
 src/dialect/sqlite.rs     |  4 ++--
 tests/sqlparser_sqlite.rs | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/dialect/sqlite.rs b/src/dialect/sqlite.rs
index 37ede9fc..d549c750 100644
--- a/src/dialect/sqlite.rs
+++ b/src/dialect/sqlite.rs
@@ -79,7 +79,7 @@ impl Dialect for SQLiteDialect {
         &self,
         parser: &mut crate::parser::Parser,
         expr: &crate::ast::Expr,
-        _precedence: u8,
+        precedence: u8,
     ) -> Option<Result<crate::ast::Expr, ParserError>> {
         // Parse MATCH, REGEXP and GLOB as operators
         // See <https://www.sqlite.org/lang_expr.html#the_like_glob_regexp_match_and_extract_operators>
@@ -90,7 +90,7 @@ impl Dialect for SQLiteDialect {
         ] {
             if parser.parse_keyword(keyword) {
                 let left = Box::new(expr.clone());
-                let right = Box::new(match parser.parse_expr() {
+                let right = Box::new(match parser.parse_subexpr(precedence) {
                     Ok(expr) => expr,
                     Err(e) => return Some(Err(e)),
                 });
diff --git a/tests/sqlparser_sqlite.rs b/tests/sqlparser_sqlite.rs
index b72d294f..a017562d 100644
--- a/tests/sqlparser_sqlite.rs
+++ b/tests/sqlparser_sqlite.rs
@@ -926,6 +926,37 @@ fn test_drop_trigger() {
     }
 }
 
+#[test]
+fn parse_pattern_operators_bind_at_like_precedence() {
+    fn where_operator(sql: &str) -> BinaryOperator {
+        let Statement::Query(query) = sqlite().verified_stmt(sql) else {
+            panic!("expected a query");
+        };
+        let SetExpr::Select(select) = *query.body else {
+            panic!("expected a select");
+        };
+        let Some(Expr::BinaryOp { op, .. }) = select.selection else {
+            panic!("expected a WHERE binary operator");
+        };
+        op
+    }
+
+    // Above AND, so the pattern does not swallow the rest of the expression.
+    for operator in ["REGEXP", "MATCH", "GLOB", "LIKE"] {
+        let sql = format!("SELECT 1 FROM t WHERE a {operator} 'p' AND b = 1");
+        assert_eq!(where_operator(&sql), BinaryOperator::And, "{operator}");
+    }
+    // Below string concatenation, so the pattern is not cut short either.
+    for (operator, expected) in [
+        ("REGEXP", BinaryOperator::Regexp),
+        ("MATCH", BinaryOperator::Match),
+        ("GLOB", BinaryOperator::Glob),
+    ] {
+        let sql = format!("SELECT 1 FROM t WHERE a {operator} 'p' || 'q'");
+        assert_eq!(where_operator(&sql), expected, "{operator}");
+    }
+}
+
 fn sqlite() -> TestedDialects {
     TestedDialects::new(vec![Box::new(SQLiteDialect {})])
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org