Trait datafusion_expr::expr_rewriter::ExprRewriter
source · pub trait ExprRewriter<E: ExprRewritable = Expr>: Sized {
// Required method
fn mutate(&mut self, expr: E) -> Result<E>;
// Provided method
fn pre_visit(&mut self, _expr: &E) -> Result<RewriteRecursion> { ... }
}
Expand description
Trait for potentially recursively rewriting an Expr
expression
tree. When passed to Expr::rewrite
, ExpressionVisitor::mutate
is
invoked recursively on all nodes of an expression tree.
Performs a depth first walk of an expression and its children
to rewrite an expression, consuming self
producing a new
Expr
.
Implements a modified version of the visitor
pattern to
separate algorithms from the structure of the Expr
tree and
make it easier to write new, efficient expression
transformation algorithms.
For an expression tree such as
BinaryExpr (GT)
left: Column("foo")
right: Column("bar")
The nodes are visited using the following order
pre_visit(BinaryExpr(GT))
pre_visit(Column("foo"))
mutate(Column("foo"))
pre_visit(Column("bar"))
mutate(Column("bar"))
mutate(BinaryExpr(GT))
If an Err result is returned, recursion is stopped immediately
If false
is returned on a call to pre_visit, no
children of that expression are visited, nor is mutate
called on that expression
See Also:
- [
Expr::accept
] to drive a rewriter through anExpr
rewrite_expr
: For rewriting anExpr
using functions
Required Methods§
Provided Methods§
sourcefn pre_visit(&mut self, _expr: &E) -> Result<RewriteRecursion>
fn pre_visit(&mut self, _expr: &E) -> Result<RewriteRecursion>
Invoked before any children of expr
are rewritten /
visited. Default implementation returns Ok(RewriteRecursion::Continue)