HaoYang670 commented on code in PR #5092:
URL: https://github.com/apache/arrow-datafusion/pull/5092#discussion_r1090161120


##########
datafusion/expr/src/expr_rewriter.rs:
##########
@@ -519,6 +495,49 @@ pub fn unnormalize_cols(exprs: impl IntoIterator<Item = 
Expr>) -> Vec<Expr> {
     exprs.into_iter().map(unnormalize_col).collect()
 }
 
+struct RewriterAdapter<F> {
+    f: F,
+}
+
+impl<F> ExprRewriter for RewriterAdapter<F>
+where
+    F: FnMut(Expr) -> Result<Expr>,
+{
+    fn mutate(&mut self, expr: Expr) -> Result<Expr> {
+        (self.f)(expr)
+    }
+}
+
+/// Recursively rewrite an [`Expr`] via a function.
+///
+/// Rewrites the expression bottom up by recursively calling `f(expr)`
+/// on `expr`'s children and then on expr. See [`ExprRewriter`]

Review Comment:
   ```suggestion
   /// on `expr`'s children and then on `expr`. See [`ExprRewriter`]
   ```



##########
datafusion/expr/src/expr_rewriter.rs:
##########
@@ -519,6 +495,49 @@ pub fn unnormalize_cols(exprs: impl IntoIterator<Item = 
Expr>) -> Vec<Expr> {
     exprs.into_iter().map(unnormalize_col).collect()
 }
 
+struct RewriterAdapter<F> {
+    f: F,
+}
+
+impl<F> ExprRewriter for RewriterAdapter<F>
+where
+    F: FnMut(Expr) -> Result<Expr>,
+{
+    fn mutate(&mut self, expr: Expr) -> Result<Expr> {

Review Comment:
   Can we let `ExprRewriter::mutate` return `Result<Option<E>>` in the future, 
just like what we've done for `LogicalPlan::try_optimize`?
   



##########
datafusion/expr/src/expr_rewriter.rs:
##########
@@ -519,6 +495,49 @@ pub fn unnormalize_cols(exprs: impl IntoIterator<Item = 
Expr>) -> Vec<Expr> {
     exprs.into_iter().map(unnormalize_col).collect()
 }
 
+struct RewriterAdapter<F> {

Review Comment:
   It is better to add some comments for `RewriterAdapter`, but this is not a 
blocker.



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