askoa commented on code in PR #4906:
URL: https://github.com/apache/arrow-datafusion/pull/4906#discussion_r1070290955
##########
datafusion/expr/src/expr_visitor.rs:
##########
@@ -220,3 +220,36 @@ impl ExprVisitable for Expr {
visitor.post_visit(self)
}
}
+
+struct VisitorAdapter<F, E> {
+ f: F,
+ err: std::result::Result<(), E>,
+}
+
+impl<F, E> ExpressionVisitor for VisitorAdapter<F, E>
+where
+ F: FnMut(&Expr) -> std::result::Result<(), E>,
+{
+ fn pre_visit(mut self, expr: &Expr) -> Result<Recursion<Self>> {
+ if let Err(e) = (self.f)(expr) {
+ // save the error for later (it may not be a DataFusionError
+ self.err = Err(e);
+ Ok(Recursion::Stop(self))
+ } else {
+ // keep going
+ Ok(Recursion::Continue(self))
+ }
+ }
+}
+
+/// Conveniece function for using a mutable function as an expression visiitor
+///
+/// TODO make this match names in physical plan
+pub fn walk_expr_down<F, E>(expr: &Expr, f: F) -> std::result::Result<(), E>
Review Comment:
:+1:
--
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]