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

github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 3af9988c MySQL: Parse bitwise shift left/right operators (#2152)
3af9988c is described below

commit 3af9988c432e3dae1a2343d60e64394f3ad9fa42
Author: Michael Victor Zink <[email protected]>
AuthorDate: Thu Jan 8 03:00:15 2026 -0800

    MySQL: Parse bitwise shift left/right operators (#2152)
---
 src/dialect/duckdb.rs     |  4 ++++
 src/dialect/generic.rs    |  4 ++++
 src/dialect/mod.rs        |  5 +++++
 src/dialect/mysql.rs      |  4 ++++
 src/dialect/postgresql.rs |  4 ++++
 src/dialect/redshift.rs   |  4 ++++
 src/parser/mod.rs         |  4 ++--
 tests/sqlparser_common.rs | 23 +++++++++++++++++++++++
 8 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/dialect/duckdb.rs b/src/dialect/duckdb.rs
index f08d827b..ea099013 100644
--- a/src/dialect/duckdb.rs
+++ b/src/dialect/duckdb.rs
@@ -43,6 +43,10 @@ impl Dialect for DuckDbDialect {
         true
     }
 
+    fn supports_bitwise_shift_operators(&self) -> bool {
+        true
+    }
+
     fn supports_named_fn_args_with_eq_operator(&self) -> bool {
         true
     }
diff --git a/src/dialect/generic.rs b/src/dialect/generic.rs
index bbedbc05..f3a0903a 100644
--- a/src/dialect/generic.rs
+++ b/src/dialect/generic.rs
@@ -132,6 +132,10 @@ impl Dialect for GenericDialect {
         true
     }
 
+    fn supports_bitwise_shift_operators(&self) -> bool {
+        true
+    }
+
     fn supports_comment_on(&self) -> bool {
         true
     }
diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs
index 1a416e4d..0b621297 100644
--- a/src/dialect/mod.rs
+++ b/src/dialect/mod.rs
@@ -894,6 +894,11 @@ pub trait Dialect: Debug + Any {
         false
     }
 
+    /// Returns true if the dialect supports `<<` and `>>` shift operators.
+    fn supports_bitwise_shift_operators(&self) -> bool {
+        false
+    }
+
     /// Returns true if the dialect supports nested comments
     /// e.g. `/* /* nested */ */`
     fn supports_nested_comments(&self) -> bool {
diff --git a/src/dialect/mysql.rs b/src/dialect/mysql.rs
index 8d2a5ad4..53a30f18 100644
--- a/src/dialect/mysql.rs
+++ b/src/dialect/mysql.rs
@@ -84,6 +84,10 @@ impl Dialect for MySqlDialect {
         true
     }
 
+    fn supports_bitwise_shift_operators(&self) -> bool {
+        true
+    }
+
     fn parse_infix(
         &self,
         parser: &mut crate::parser::Parser,
diff --git a/src/dialect/postgresql.rs b/src/dialect/postgresql.rs
index e861cc51..02bab0e0 100644
--- a/src/dialect/postgresql.rs
+++ b/src/dialect/postgresql.rs
@@ -199,6 +199,10 @@ impl Dialect for PostgreSqlDialect {
         true
     }
 
+    fn supports_bitwise_shift_operators(&self) -> bool {
+        true
+    }
+
     /// see <https://www.postgresql.org/docs/current/sql-comment.html>
     fn supports_comment_on(&self) -> bool {
         true
diff --git a/src/dialect/redshift.rs b/src/dialect/redshift.rs
index 1cd6098a..43c0646c 100644
--- a/src/dialect/redshift.rs
+++ b/src/dialect/redshift.rs
@@ -120,6 +120,10 @@ impl Dialect for RedshiftSqlDialect {
         true
     }
 
+    fn supports_bitwise_shift_operators(&self) -> bool {
+        true
+    }
+
     fn supports_array_typedef_with_brackets(&self) -> bool {
         true
     }
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 4e914df7..3294acf6 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -3485,10 +3485,10 @@ impl<'a> Parser<'a> {
             Token::DuckIntDiv if dialect_is!(dialect is DuckDbDialect | 
GenericDialect) => {
                 Some(BinaryOperator::DuckIntegerDivide)
             }
-            Token::ShiftLeft if dialect_is!(dialect is PostgreSqlDialect | 
DuckDbDialect | GenericDialect | RedshiftSqlDialect) => {
+            Token::ShiftLeft if dialect.supports_bitwise_shift_operators() => {
                 Some(BinaryOperator::PGBitwiseShiftLeft)
             }
-            Token::ShiftRight if dialect_is!(dialect is PostgreSqlDialect | 
DuckDbDialect | GenericDialect | RedshiftSqlDialect) => {
+            Token::ShiftRight if dialect.supports_bitwise_shift_operators() => 
{
                 Some(BinaryOperator::PGBitwiseShiftRight)
             }
             Token::Sharp if dialect_is!(dialect is PostgreSqlDialect | 
RedshiftSqlDialect) => {
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 9f549e4d..365bddb0 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -2369,6 +2369,29 @@ fn parse_bitwise_ops() {
     }
 }
 
+#[test]
+fn parse_bitwise_shift_ops() {
+    let dialects = all_dialects_where(|d| 
d.supports_bitwise_shift_operators());
+    let sql = "SELECT 1 << 2, 3 >> 4";
+    let select = dialects.verified_only_select(sql);
+    assert_eq!(
+        SelectItem::UnnamedExpr(Expr::BinaryOp {
+            left: Box::new(Expr::Value((number("1")).with_empty_span())),
+            op: BinaryOperator::PGBitwiseShiftLeft,
+            right: Box::new(Expr::Value((number("2")).with_empty_span())),
+        }),
+        select.projection[0]
+    );
+    assert_eq!(
+        SelectItem::UnnamedExpr(Expr::BinaryOp {
+            left: Box::new(Expr::Value((number("3")).with_empty_span())),
+            op: BinaryOperator::PGBitwiseShiftRight,
+            right: Box::new(Expr::Value((number("4")).with_empty_span())),
+        }),
+        select.projection[1]
+    );
+}
+
 #[test]
 fn parse_binary_any() {
     let select = verified_only_select("SELECT a = ANY(b)");


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to