AssHero commented on code in PR #2958:
URL: https://github.com/apache/arrow-datafusion/pull/2958#discussion_r928268943


##########
datafusion/optimizer/src/simplify_expressions.rs:
##########
@@ -185,6 +181,97 @@ fn as_bool_lit(expr: Expr) -> Option<bool> {
     }
 }
 
+/// negate a Not clause
+/// input is the clause to be negated.(args of Not clause)
+/// For BinaryExpr, use the negator of op instead.
+///    not ( A > B) ===> (A <= B)
+/// For BoolExpr, not (A and B) ===> (not A) or (not B)
+///     not (A or B) ===> (not A) and (not B)
+///     not (not A) ===> A
+/// For NullExpr, not (A is not null) ===> A is null
+///     not (A is null) ===> A is not null
+/// For InList, not (A not in (..)) ===> A in (..)
+///     not (A in (..)) ===> A not in (..)
+/// For Between, not (A between B and C) ===> (A not between B and C)
+///     not (A not between B and C) ===> (A between B and C)
+/// For others, use Not clause
+fn negate_clause(expr: Expr) -> Expr {
+    match expr {
+        Expr::BinaryExpr { left, op, right } => {
+            match op {
+                // not (A = B) ===> (A <> B)
+                Operator::Eq => binary_expr(*left, Operator::NotEq, *right),

Review Comment:
   I think it's better than new allocation.  Let me fix this. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to