You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by lu...@apache.org on 2026/10/18 15:57:48 UTC

(datafusion-sqlparser-rs) branch upstream/sqlite-bitwise-precedence created (now 43100761f)

This is an automated email from the ASF dual-hosted git repository.

LucaCappelletti94 pushed a change to branch upstream/sqlite-bitwise-precedence
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


      at 43100761f SQLite: Parse & and | at the same precedence

This branch includes the following new commits:

     new 43100761f SQLite: Parse & and | at the same precedence

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: SQLite: Parse & and | at the same precedence

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

LucaCappelletti94 pushed a commit to branch upstream/sqlite-bitwise-precedence
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit 43100761f1560a04505e2b4194ce9d822121810b
Author: LucaCappelletti94 <ca...@gmail.com>
AuthorDate: Sun Oct 18 17:57:38 2026 +0200

    SQLite: Parse & and | at the same precedence
---
 src/dialect/sqlite.rs     | 12 +++++++++-
 tests/sqlparser_sqlite.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/src/dialect/sqlite.rs b/src/dialect/sqlite.rs
index f63e4cbe1..70833d804 100644
--- a/src/dialect/sqlite.rs
+++ b/src/dialect/sqlite.rs
@@ -20,9 +20,10 @@ use alloc::boxed::Box;
 
 use crate::ast::BinaryOperator;
 use crate::ast::{Expr, Statement};
-use crate::dialect::Dialect;
+use crate::dialect::{Dialect, Precedence};
 use crate::keywords::Keyword;
 use crate::parser::{Parser, ParserError};
+use crate::tokenizer::Token;
 
 /// A [`Dialect`] for [SQLite](https://www.sqlite.org)
 ///
@@ -97,6 +98,15 @@ impl Dialect for SQLiteDialect {
         None
     }
 
+    /// `&` and `|` share one left-associative precedence level.
+    /// See <https://www.sqlite.org/lang_expr.html#operators_and_parse_affecting_attributes>
+    fn get_next_precedence(&self, parser: &Parser) -> Option<Result<u8, ParserError>> {
+        match parser.peek_token_ref().token {
+            Token::Ampersand | Token::Pipe => Some(Ok(self.prec_value(Precedence::Ampersand))),
+            _ => None,
+        }
+    }
+
     fn supports_in_empty_list(&self) -> bool {
         true
     }
diff --git a/tests/sqlparser_sqlite.rs b/tests/sqlparser_sqlite.rs
index 2e60c75ef..46222e827 100644
--- a/tests/sqlparser_sqlite.rs
+++ b/tests/sqlparser_sqlite.rs
@@ -1171,3 +1171,63 @@ fn test_dollar_sign_in_identifier() {
         .parse_sql_statements("SELECT a$ FROM t")
         .unwrap_err();
 }
+
+#[test]
+fn parse_bitwise_and_or_share_precedence() {
+    fn num(n: &str) -> Expr {
+        Expr::value(number(n))
+    }
+    fn bin(left: Expr, op: BinaryOperator, right: Expr) -> Expr {
+        Expr::BinaryOp {
+            left: Box::new(left),
+            op,
+            right: Box::new(right),
+        }
+    }
+    use BinaryOperator::{BitwiseAnd, BitwiseOr, Eq, Multiply, Plus};
+
+    for (sql, expected) in [
+        (
+            "6 | 1 & 3",
+            bin(bin(num("6"), BitwiseOr, num("1")), BitwiseAnd, num("3")),
+        ),
+        (
+            "6 & 3 | 8",
+            bin(bin(num("6"), BitwiseAnd, num("3")), BitwiseOr, num("8")),
+        ),
+        (
+            "1 & 2 & 3",
+            bin(bin(num("1"), BitwiseAnd, num("2")), BitwiseAnd, num("3")),
+        ),
+        (
+            "1 | 2 | 3",
+            bin(bin(num("1"), BitwiseOr, num("2")), BitwiseOr, num("3")),
+        ),
+        (
+            "1 | 2 + 3 & 4 * 5",
+            bin(
+                bin(num("1"), BitwiseOr, bin(num("2"), Plus, num("3"))),
+                BitwiseAnd,
+                bin(num("4"), Multiply, num("5")),
+            ),
+        ),
+        (
+            "6 | (1 & 3)",
+            bin(
+                num("6"),
+                BitwiseOr,
+                Expr::Nested(Box::new(bin(num("1"), BitwiseAnd, num("3")))),
+            ),
+        ),
+        (
+            "1 | 2 = 3 & 4",
+            bin(
+                bin(num("1"), BitwiseOr, num("2")),
+                Eq,
+                bin(num("3"), BitwiseAnd, num("4")),
+            ),
+        ),
+    ] {
+        assert_eq!(sqlite().verified_expr(sql), expected, "{sql}");
+    }
+}


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