alamb commented on issue #3014: URL: https://github.com/apache/arrow-datafusion/issues/3014#issuecomment-1204494306
@iajoiner I see -- you want to annotate the entire tree Here is what I recommend: 1. add `children()` and `new_with_children` to the `PhysicalExpr` trait that will allow you to walk the tree, following the model of `ExecutionPlan`: https://docs.rs/datafusion/10.0.0/datafusion/physical_plan/trait.ExecutionPlan.html#tymethod.children https://docs.rs/datafusion/10.0.0/datafusion/physical_plan/trait.ExecutionPlan.html#tymethod.with_new_children ```rust pub trait PhysicalExpr { .... fn children(&self) -> [&dyn PhysicalExpr]; } ``` 2. write a function that recursively wraps all nodes in a a tree with your wrapper (bonus points for writing something like `ExprRewriter` but for `PhysicalExprs` - see https://docs.rs/datafusion/10.0.0/datafusion/physical_plan/trait.ExecutionPlanVisitor.html and https://docs.rs/datafusion/10.0.0/datafusion/logical_plan/trait.ExprRewriter.html for inspiration ```rust fn wrap_one_expr(expr: Arc<dyn PhysicalExpr>) -> Arc<dyn PhysicalExpr> { // make whatever wrapper type you want here Arc::new(MyWrapper(expr)) } /// Calls `wrap_one_expr` on all children in a tree of `PhysicalExpr`: fn wrap_all_nodes(root: Arc<dyn PhysicalExpr>) -> Arc<dyn PhysicalExpr> { // recursively wrap all children: let wrapped_children = root .children() .into_iter() .map(wrap_all_nodes) .collect::<Vec<_>>(); // create newly wrapped root node wrap_one_expr(root.new_with_children(wrapped_children)) } ``` What do you think? -- 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]
