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/09/22 08:44:38 UTC

(datafusion-sqlparser-rs) branch prefix-bang-display-space updated (bcc911bc -> fdbb7ce7)

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

LucaCappelletti94 pushed a change to branch prefix-bang-display-space
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


 discard bcc911bc Generic: Render prefix ! operator with space before operator characters
     new fdbb7ce7 Generic: Render prefix ! operator with space before operator characters

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (bcc911bc)
            \
             N -- N -- N   refs/heads/prefix-bang-display-space (fdbb7ce7)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 src/ast/mod.rs | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)


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


(datafusion-sqlparser-rs) 01/01: Generic: Render prefix ! operator with space before operator characters

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

LucaCappelletti94 pushed a commit to branch prefix-bang-display-space
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit fdbb7ce73a7ea6949b44f224425f3b47188b431e
Author: LucaCappelletti94 <ca...@gmail.com>
AuthorDate: Tue Sep 22 10:05:13 2026 +0200

    Generic: Render prefix ! operator with space before operator characters
---
 src/ast/mod.rs            | 30 ++++++++++++------------------
 tests/sqlparser_common.rs | 14 ++++++++++++++
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index dcfd1a96..b59f7fbd 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -1965,7 +1965,7 @@ impl fmt::Display for Expr {
                 | UnaryOperator::PGAbs
                 | UnaryOperator::QuestionDash
                 | UnaryOperator::QuestionPipe => write!(f, "{op} {expr}"),
-                UnaryOperator::Minus => {
+                UnaryOperator::Minus | UnaryOperator::BangNot => {
                     if starts_with_operator_char(expr) {
                         write!(f, "{op} {expr}")
                     } else {
@@ -1973,7 +1973,6 @@ impl fmt::Display for Expr {
                     }
                 }
                 UnaryOperator::Plus
-                | UnaryOperator::BangNot
                 | UnaryOperator::PGPrefixFactorial
                 | UnaryOperator::PGSquareRoot
                 | UnaryOperator::PGCubeRoot => write!(f, "{op}{expr}"),
@@ -8089,24 +8088,19 @@ impl fmt::Display for FunctionArg {
     }
 }
 
-/// Whether `expr` renders with an operator character first. A prefix `-`
-/// must not abut one, since `--` starts a line comment and operator-run
-/// dialects fuse `-@`, `-~`, `-#`, `-!!` and `-||/` into single tokens.
+/// Whether `expr` renders with an operator character first. A prefix `-` or `!`
+/// must not abut one, since `--` starts a line comment and compound tokens
+/// like `!!` or `!~` alter the parsed AST or fail to parse.
 fn starts_with_operator_char(expr: &Expr) -> bool {
-    use fmt::Write;
-    struct FirstChar(Option<char>);
-    impl fmt::Write for FirstChar {
-        fn write_str(&mut self, s: &str) -> fmt::Result {
-            if self.0.is_none() {
-                self.0 = s.chars().next();
-            }
-            Ok(())
-        }
+    match expr {
+        Expr::UnaryOp { op, expr } => match op {
+            UnaryOperator::PGPostfixFactorial => starts_with_operator_char(expr),
+            UnaryOperator::Not => false,
+            _ => true,
+        },
+        Expr::BinaryOp { left, .. } => starts_with_operator_char(left),
+        _ => false,
     }
-    let mut first = FirstChar(None);
-    let _ = write!(first, "{expr}");
-    const OPERATOR_CHARS: &str = "+-*/<>=~!@%#^&|";
-    first.0.is_some_and(|c| OPERATOR_CHARS.contains(c))
 }
 
 /// `FunctionArgOperator::Space` has no token of its own, so the name and the
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index c4aa607d..63aa2a7d 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -20080,3 +20080,17 @@ fn parse_unary_minus_never_renders_line_comment() {
     all_dialects().verified_stmt("SELECT -1");
     all_dialects().verified_stmt("SELECT -x");
 }
+
+#[test]
+fn parse_bang_not_renders_apart_from_operand() {
+    let dialects = all_dialects_where(|d| d.supports_bang_not_operator());
+    dialects.verified_stmt("SELECT ! !a");
+    dialects.verified_stmt("SELECT ! ! !a");
+    dialects.verified_stmt("SELECT ! ~ a");
+    dialects.verified_stmt("SELECT ! -a");
+    dialects.verified_stmt("SELECT ! +a");
+    dialects.verified_stmt("SELECT !a");
+    dialects.verified_stmt("SELECT !(b > 3)");
+    dialects.verified_stmt("SET eaac_cion = ! !o");
+    dialects.one_statement_parses_to("SET eaac_cion = ! ! o", "SET eaac_cion = ! !o");
+}


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