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

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

Apply the closure F to the node’s children

source

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

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>where F: FnMut(&Self) -> Result<VisitRecursion>,

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: TreeNodeVisitor<N = Self>>( &self, visitor: &mut V ) -> Result<VisitRecursion>

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>where F: Fn(Self) -> Result<Transformed<Self>>,

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>where F: Fn(Self) -> Result<Transformed<Self>>,

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_up<F>(self, op: &F) -> Result<Self>where F: Fn(Self) -> Result<Transformed<Self>>,

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 rewrite<R: TreeNodeRewriter<N = Self>>( self, rewriter: &mut R ) -> Result<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.

Implementations on Foreign Types§

source§

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

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

source§

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

source§

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

Implementors§