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/09/21 15:04:19 UTC
(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2533-3fd342fe823f8bd787b574adf3074d0b4da59b91 created (now 6f72be09)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-2533-3fd342fe823f8bd787b574adf3074d0b4da59b91
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
at 6f72be09 Render prefix ~ operator with a space (#2533)
This branch includes the following new commits:
new 6f72be09 Render prefix ~ operator with a space (#2533)
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: Render prefix ~ operator with a space (#2533)
Posted by gi...@apache.org.
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-2533-3fd342fe823f8bd787b574adf3074d0b4da59b91
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit 6f72be0984c5b3c6d7deeffcba761b0b361851d4
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Mon Sep 21 15:03:55 2026 +0000
Render prefix ~ operator with a space (#2533)
---
src/ast/mod.rs | 35 +++++++++++++++++------------------
tests/sqlparser_common.rs | 22 +++++++++++++++++-----
tests/sqlparser_postgres.rs | 7 +++++++
3 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index b6d67df5..4817a3f0 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -1955,24 +1955,23 @@ impl fmt::Display for Expr {
if add_parens { ")" } else { "" },
)
}
- Expr::UnaryOp { op, expr } => {
- if op == &UnaryOperator::PGPostfixFactorial {
- write!(f, "{expr}{op}")
- } else if matches!(
- op,
- UnaryOperator::Not
- | UnaryOperator::Hash
- | UnaryOperator::AtDashAt
- | UnaryOperator::DoubleAt
- | UnaryOperator::PGAbs
- | UnaryOperator::QuestionDash
- | UnaryOperator::QuestionPipe
- ) {
- write!(f, "{op} {expr}")
- } else {
- write!(f, "{op}{expr}")
- }
- }
+ Expr::UnaryOp { op, expr } => match op {
+ UnaryOperator::PGPostfixFactorial => write!(f, "{expr}{op}"),
+ UnaryOperator::Not
+ | UnaryOperator::BitwiseNot
+ | UnaryOperator::Hash
+ | UnaryOperator::AtDashAt
+ | UnaryOperator::DoubleAt
+ | UnaryOperator::PGAbs
+ | UnaryOperator::QuestionDash
+ | UnaryOperator::QuestionPipe => write!(f, "{op} {expr}"),
+ UnaryOperator::Plus
+ | UnaryOperator::Minus
+ | UnaryOperator::BangNot
+ | UnaryOperator::PGPrefixFactorial
+ | UnaryOperator::PGSquareRoot
+ | UnaryOperator::PGCubeRoot => write!(f, "{op}{expr}"),
+ },
Expr::Convert {
is_try,
expr,
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 2de6062b..4069ff10 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -19469,11 +19469,7 @@ fn test_parse_alter_user() {
#[test]
fn parse_generic_unary_ops() {
- let unary_ops = &[
- ("~", UnaryOperator::BitwiseNot),
- ("-", UnaryOperator::Minus),
- ("+", UnaryOperator::Plus),
- ];
+ let unary_ops = &[("-", UnaryOperator::Minus), ("+", UnaryOperator::Plus)];
for (str_op, op) in unary_ops {
let select = verified_only_select(&format!("SELECT {}expr", str_op));
assert_eq!(
@@ -19484,6 +19480,16 @@ fn parse_generic_unary_ops() {
select.projection[0]
);
}
+
+ let select = verified_only_select("SELECT ~ expr");
+ assert_eq!(
+ UnnamedExpr(UnaryOp {
+ op: UnaryOperator::BitwiseNot,
+ expr: Box::new(Identifier(Ident::new("expr"))),
+ }),
+ select.projection[0]
+ );
+ one_statement_parses_to("SELECT ~expr", "SELECT ~ expr");
}
#[test]
@@ -20060,3 +20066,9 @@ fn parse_insert_by_name() {
_ => unreachable!(),
}
}
+
+#[test]
+fn parse_bitwise_not_renders_apart_from_operand() {
+ all_dialects().verified_stmt("SELECT ~ -1");
+ all_dialects().verified_stmt("SELECT ~ ~ 1");
+}
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index c85cb26f..bf535383 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -9968,3 +9968,10 @@ fn parse_pg_abs_space_before_negative_operand() {
err
);
}
+
+#[test]
+fn parse_bitwise_not_before_pg_prefix_operators() {
+ pg().one_statement_parses_to("SELECT ~ @2", "SELECT ~ @ 2");
+ pg().verified_stmt("SELECT ~ @ 2");
+ pg().one_statement_parses_to("SELECT ~ #x", "SELECT ~ # x");
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org