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

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new ccd850bef0 feat: Not  expr to string (#9802)
ccd850bef0 is described below

commit ccd850bef0706664e49d792d0442c0ac16df866b
Author: Sebastian Espinosa <[email protected]>
AuthorDate: Tue Mar 26 22:04:14 2024 -0500

    feat: Not  expr to string (#9802)
    
    * feat: Not  expr to string
    
    * fix: use not logical expr
    
    * fix: format using fmt
    
    * fix: import within test mod
    
    * fix: format new import
---
 datafusion/sql/src/unparser/expr.rs | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/datafusion/sql/src/unparser/expr.rs 
b/datafusion/sql/src/unparser/expr.rs
index 8610269bdb..a29b5014b1 100644
--- a/datafusion/sql/src/unparser/expr.rs
+++ b/datafusion/sql/src/unparser/expr.rs
@@ -24,7 +24,9 @@ use datafusion_expr::{
     expr::{AggregateFunctionDefinition, Alias, InList, ScalarFunction, 
WindowFunction},
     Between, BinaryExpr, Case, Cast, Expr, Like, Operator,
 };
-use sqlparser::ast::{self, Function, FunctionArg, Ident};
+use sqlparser::ast::{
+    self, Expr as AstExpr, Function, FunctionArg, Ident, UnaryOperator,
+};
 
 use super::Unparser;
 
@@ -267,6 +269,13 @@ impl Unparser<'_> {
             Expr::IsUnknown(expr) => {
                 Ok(ast::Expr::IsUnknown(Box::new(self.expr_to_sql(expr)?)))
             }
+            Expr::Not(expr) => {
+                let sql_parser_expr = self.expr_to_sql(expr)?;
+                Ok(AstExpr::UnaryOp {
+                    op: UnaryOperator::Not,
+                    expr: Box::new(sql_parser_expr),
+                })
+            }
             _ => not_impl_err!("Unsupported expression: {expr:?}"),
         }
     }
@@ -619,8 +628,8 @@ mod tests {
 
     use datafusion_common::TableReference;
     use datafusion_expr::{
-        case, col, expr::AggregateFunction, lit, ColumnarValue, ScalarUDF, 
ScalarUDFImpl,
-        Signature, Volatility,
+        case, col, expr::AggregateFunction, lit, not, ColumnarValue, ScalarUDF,
+        ScalarUDFImpl, Signature, Volatility,
     };
 
     use crate::unparser::dialect::CustomDialect;
@@ -782,6 +791,7 @@ mod tests {
                 (col("a") + col("b")).gt(lit(4)).is_unknown(),
                 r#"(("a" + "b") > 4) IS UNKNOWN"#,
             ),
+            (not(col("a")), r#"NOT "a""#),
             (
                 Expr::between(col("a"), lit(1), lit(7)),
                 r#"("a" BETWEEN 1 AND 7)"#,

Reply via email to