pub trait TreeNode: Sized {
    // Required methods
    fn apply_children<F>(
        &self,
        op: &mut F
    ) -> Result<VisitRecursion, DataFusionError>
       where F: FnMut(&Self) -> Result<VisitRecursion, DataFusionError>;
    fn map_children<F>(self, transform: F) -> Result<Self, DataFusionError>
       where F: FnMut(Self) -> Result<Self, DataFusionError>;

    // Provided methods
    fn apply<F>(&self, op: &mut F) -> Result<VisitRecursion, DataFusionError>
       where F: FnMut(&Self) -> Result<VisitRecursion, DataFusionError> { ... }
    fn visit<V>(
        &self,
        visitor: &mut V
    ) -> Result<VisitRecursion, DataFusionError>
       where V: TreeNodeVisitor<N = Self> { ... }
    fn transform<F>(self, op: &F) -> Result<Self, DataFusionError>
       where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError> { ... }
    fn transform_down<F>(self, op: &F) -> Result<Self, DataFusionError>
       where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError> { ... }
    fn transform_down_mut<F>(self, op: &mut F) -> Result<Self, DataFusionError>
       where F: FnMut(Self) -> Result<Transformed<Self>, DataFusionError> { ... }
    fn transform_up<F>(self, op: &F) -> Result<Self, DataFusionError>
       where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError> { ... }
    fn transform_up_mut<F>(self, op: &mut F) -> Result<Self, DataFusionError>
       where F: FnMut(Self) -> Result<Transformed<Self>, DataFusionError> { ... }
    fn rewrite<R>(self, rewriter: &mut R) -> Result<Self, DataFusionError>
       where R: TreeNodeRewriter<N = Self> { ... }
}
Expand description

Defines a visitable and rewriteable a tree node. This trait is implemented for plans (ExecutionPlan and LogicalPlan) as well as expression trees (PhysicalExpr, Expr) in DataFusion

Required Methods§

source

fn apply_children<F>( &self, op: &mut F ) -> Result<VisitRecursion, DataFusionError>where F: FnMut(&Self) -> Result<VisitRecursion, DataFusionError>,

Apply the closure F to the node’s children

source

fn map_children<F>(self, transform: F) -> Result<Self, DataFusionError>where F: FnMut(Self) -> Result<Self, DataFusionError>,

Apply transform F to the node’s children, the transform F might have a direction(Preorder or Postorder)

Provided Methods§

source

fn apply<F>(&self, op: &mut F) -> Result<VisitRecursion, DataFusionError>where F: FnMut(&Self) -> Result<VisitRecursion, DataFusionError>,

Use preorder to iterate the node on the tree so that we can stop fast for some cases.

The op closure can be used to collect some info from the tree node or do some checking for the tree node.

source

fn visit<V>(&self, visitor: &mut V) -> Result<VisitRecursion, DataFusionError>where V: TreeNodeVisitor<N = Self>,

Visit the tree node using the given TreeNodeVisitor It performs a depth first walk of an node and its children.

For an node tree such as

ParentNode
   left: ChildNode1
   right: ChildNode2

The nodes are visited using the following order

pre_visit(ParentNode)
pre_visit(ChildNode1)
post_visit(ChildNode1)
pre_visit(ChildNode2)
post_visit(ChildNode2)
post_visit(ParentNode)

If an Err result is returned, recursion is stopped immediately

If VisitRecursion::Stop is returned on a call to pre_visit, no children of that node will be visited, nor is post_visit called on that node. Details see TreeNodeVisitor

If using the default TreeNodeVisitor::post_visit that does nothing, Self::apply should be preferred.

source

fn transform<F>(self, op: &F) -> Result<Self, DataFusionError>where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,

Convenience utils for writing optimizers rule: recursively apply the given op to the node tree. When op does not apply to a given node, it is left unchanged. The default tree traversal direction is transform_up(Postorder Traversal).

source

fn transform_down<F>(self, op: &F) -> Result<Self, DataFusionError>where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,

Convenience utils for writing optimizers rule: recursively apply the given ‘op’ to the node and all of its children(Preorder Traversal). When the op does not apply to a given node, it is left unchanged.

source

fn transform_down_mut<F>(self, op: &mut F) -> Result<Self, DataFusionError>where F: FnMut(Self) -> Result<Transformed<Self>, DataFusionError>,

Convenience utils for writing optimizers rule: recursively apply the given ‘op’ to the node and all of its children(Preorder Traversal) using a mutable function, F. When the op does not apply to a given node, it is left unchanged.

source

fn transform_up<F>(self, op: &F) -> Result<Self, DataFusionError>where F: Fn(Self) -> Result<Transformed<Self>, DataFusionError>,

Convenience utils for writing optimizers rule: recursively apply the given ‘op’ first to all of its children and then itself(Postorder Traversal). When the op does not apply to a given node, it is left unchanged.

source

fn transform_up_mut<F>(self, op: &mut F) -> Result<Self, DataFusionError>where F: FnMut(Self) -> Result<Transformed<Self>, DataFusionError>,

Convenience utils for writing optimizers rule: recursively apply the given ‘op’ first to all of its children and then itself(Postorder Traversal) using a mutable function, F. When the op does not apply to a given node, it is left unchanged.

source

fn rewrite<R>(self, rewriter: &mut R) -> Result<Self, DataFusionError>where R: TreeNodeRewriter<N = Self>,

Transform the tree node using the given TreeNodeRewriter It performs a depth first walk of an node and its children.

For an node tree such as

ParentNode
   left: ChildNode1
   right: ChildNode2

The nodes are visited using the following order

pre_visit(ParentNode)
pre_visit(ChildNode1)
mutate(ChildNode1)
pre_visit(ChildNode2)
mutate(ChildNode2)
mutate(ParentNode)

If an Err result is returned, recursion is stopped immediately

If false is returned on a call to pre_visit, no children of that node will be visited, nor is mutate called on that node

If using the default TreeNodeRewriter::pre_visit which returns true, Self::transform should be preferred.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> TreeNode for Arc<T>where T: DynTreeNode + ?Sized,

Blanket implementation for Arc for any tye that implements DynTreeNode (such as Arc<dyn PhysicalExpr>)

Implementors§