You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
Currently, there are many duplicated code related to the visitor trait and rewrite trait. And the trait methods are sometimes misused.
Describe the solution you'd like
Combine the visitor and rewrite trait to be one trait TreeNode and provide common behavior for ExecutionPlan, PhysicalExpr, LogicalExpr, LogicalPlan. And this trait contains the following methods:
fn get_children(&self) -> Vec<Self>; for getting its children
fn collect<F>(&self, op: &mut F) -> Result<()> where F: FnMut(&Self) -> Result<Recursion>, for collecting info from the tree node by a closure
fn visit<V: TreeNodeVisitor<N = Self>>(&self, visitor: &mut V) -> Result<Recursion> for collecting info from the tree node by a visitor. This is used when need to collect info from a specific post_visit. If only pre_visit is needed, then the collect method is preferred.
fn transform_down<F>(self, op: &F) -> Result<Self> where F: Fn(Self) -> Result<Option<Self>>, for rewriting the node from top to down
fn transform_up<F>(self, op: &F) -> Result<Self> where F: Fn(Self) -> Result<Option<Self>>, for rewriting the node from bottom to up
fn rewrite<R: TreeNodeRewriter<N = Self>>(self, rewriter: &mut R) -> Result<Self> for rewriting the node from top to down. This is used when need to invoke a specific pre_visit. Otherwise, either the transform_down or transform_up is preferred.
fn map_children<F>(self, transform: F) -> Result<Self> where F: FnMut(Self) -> Result<Self> is for replacing all of its children with the rewritted ones
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered:
yahoNanJing
changed the title
Replace the Visitor by Closure
Introduce a common trait TreeNode for ExecutionPlan, PhysicalExpr, LogicalExpr, LogicalPlan
Mar 17, 2023
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
Currently, there are many duplicated code related to the visitor trait and rewrite trait. And the trait methods are sometimes misused.
Describe the solution you'd like
Combine the visitor and rewrite trait to be one trait
TreeNode
and provide common behavior forExecutionPlan
,PhysicalExpr
,LogicalExpr
,LogicalPlan
. And this trait contains the following methods:fn get_children(&self) -> Vec<Self>;
for getting its childrenfn collect<F>(&self, op: &mut F) -> Result<()> where F: FnMut(&Self) -> Result<Recursion>,
for collecting info from the tree node by a closurefn visit<V: TreeNodeVisitor<N = Self>>(&self, visitor: &mut V) -> Result<Recursion>
for collecting info from the tree node by a visitor. This is used when need to collect info from a specificpost_visit
. If onlypre_visit
is needed, then thecollect
method is preferred.fn transform_down<F>(self, op: &F) -> Result<Self> where F: Fn(Self) -> Result<Option<Self>>,
for rewriting the node from top to downfn transform_up<F>(self, op: &F) -> Result<Self> where F: Fn(Self) -> Result<Option<Self>>,
for rewriting the node from bottom to upfn rewrite<R: TreeNodeRewriter<N = Self>>(self, rewriter: &mut R) -> Result<Self>
for rewriting the node from top to down. This is used when need to invoke a specificpre_visit
. Otherwise, either thetransform_down
ortransform_up
is preferred.fn map_children<F>(self, transform: F) -> Result<Self> where F: FnMut(Self) -> Result<Self>
is for replacing all of its children with the rewritted onesDescribe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: