You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/15 11:06:14 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #3836: Refactor `Expr::Like`, `Expr::ILike`, `Expr::SimilarTo` to use a struct

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


##########
datafusion/expr/src/expr.rs:
##########
@@ -101,26 +101,11 @@ pub enum Expr {
         right: Box<Expr>,
     },
     /// LIKE expression
-    Like {
-        negated: bool,
-        expr: Box<Expr>,
-        pattern: Box<Expr>,
-        escape_char: Option<char>,
-    },
+    Like(Like),

Review Comment:
   That is a nice reduction in replication 👍 



##########
datafusion/expr/src/expr.rs:
##########
@@ -580,39 +591,24 @@ impl Not for Expr {
 
     fn not(self) -> Self::Output {
         match self {
-            Expr::Like {
-                negated,
-                expr,
-                pattern,
-                escape_char,
-            } => Expr::Like {
-                negated: !negated,
-                expr,
-                pattern,
-                escape_char,
-            },
-            Expr::ILike {
-                negated,
-                expr,
-                pattern,
-                escape_char,
-            } => Expr::ILike {
-                negated: !negated,
-                expr,
-                pattern,
-                escape_char,
-            },
-            Expr::SimilarTo {
-                negated,
-                expr,
-                pattern,
-                escape_char,
-            } => Expr::SimilarTo {
-                negated: !negated,
-                expr,
-                pattern,
-                escape_char,
-            },
+            Expr::Like(like) => Expr::Like(Like::new(
+                !like.negated,
+                like.expr,
+                like.pattern,
+                like.escape_char,
+            )),

Review Comment:
   Another way you can write this type of match is like 
   
   ```suggestion
               Expr::Like(Like { negated, expr, pattern, escape_char} ) => Expr::Like(Like::new(
                   negated,
                   expr,
                   pattern,
                   escape_char,
               )),
   ```
   
   The benefit of doing so is that if any new field is added to `Like` the compiler will force you to update all places that use `Like` to add the new field where as this way you would have to find them manually
   
   



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org