mrob95 commented on code in PR #2772:
URL: https://github.com/apache/arrow-datafusion/pull/2772#discussion_r904963957


##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -553,22 +553,33 @@ fn is_compare_op(op: Operator) -> bool {
 
 /// replaces a column with an old name with a new name in an expression
 fn rewrite_column_expr(
-    expr: &Expr,
+    e: Expr,
     column_old: &Column,
     column_new: &Column,
 ) -> Result<Expr> {
-    let expressions = utils::expr_sub_expressions(expr)?;
-    let expressions = expressions
-        .iter()
-        .map(|e| rewrite_column_expr(e, column_old, column_new))
-        .collect::<Result<Vec<_>>>()?;
-
-    if let Expr::Column(c) = expr {
-        if c == column_old {
-            return Ok(Expr::Column(column_new.clone()));
+    struct ColumnReplacer<'a> {
+        old: &'a Column,
+        new: &'a Column,
+    }
+
+    impl<'a> ExprRewriter for ColumnReplacer<'a> {
+        fn mutate(&mut self, expr: Expr) -> Result<Expr> {
+            if let Expr::Column(c) = &expr {
+                if c == self.old {
+                    Ok(Expr::Column(self.new.clone()))
+                } else {
+                    Ok(expr)
+                }
+            } else {
+                Ok(expr)
+            }

Review Comment:
   Nice! Didn't know about ifs-in-match-conditions



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