alamb commented on code in PR #3213:
URL: https://github.com/apache/arrow-datafusion/pull/3213#discussion_r950708851


##########
datafusion/expr/src/operator.rs:
##########
@@ -79,6 +79,26 @@ pub enum Operator {
     StringConcat,
 }
 
+impl Operator {
+    /// If the operator can be negated, return the negated operator
+    /// otherwise return None
+    pub fn negate(&self) -> Option<Operator> {

Review Comment:
   👍 



##########
datafusion/expr/src/operator.rs:
##########
@@ -79,6 +79,26 @@ pub enum Operator {
     StringConcat,
 }
 
+impl Operator {
+    /// If the operator can be negated, return the negated operator
+    /// otherwise return None
+    pub fn negate(&self) -> Option<Operator> {
+        match self {
+            Operator::Eq => Some(Operator::NotEq),
+            Operator::NotEq => Some(Operator::Eq),
+            Operator::Lt => Some(Operator::GtEq),
+            Operator::LtEq => Some(Operator::Gt),
+            Operator::Gt => Some(Operator::LtEq),
+            Operator::GtEq => Some(Operator::Lt),
+            Operator::Like => Some(Operator::NotLike),
+            Operator::NotLike => Some(Operator::Like),
+            Operator::IsDistinctFrom => Some(Operator::IsNotDistinctFrom),
+            Operator::IsNotDistinctFrom => Some(Operator::IsDistinctFrom),
+            _ => None,

Review Comment:
   I would like to suggest replacing `_` with an an explicit enumeration of all 
the other operators, like
   
   ```rust
   Operator::LeftShift | OperatiorRightShift => None
   ```
   
   The reason is so that as new operators are added, the compiler will point us 
at this code and we will get another chance to avoid bugs like 
https://github.com/apache/arrow-datafusion/pull/3167/files#r946145318
   



-- 
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