Skip to content

Commit

Permalink
params
Browse files Browse the repository at this point in the history
  • Loading branch information
jimexist committed Feb 8, 2022
1 parent 4022d32 commit 3768d8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions datafusion/src/logical_plan/expr_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ pub enum RewriteRecursion {
/// tree. When passed to `Expr::rewrite`, `ExpressionVisitor::mutate` is
/// invoked recursively on all nodes of an expression tree. See the
/// comments on `Expr::rewrite` for details on its use
pub trait ExprRewriter: Sized {
pub trait ExprRewriter<E: ExprRewritable = Expr>: Sized {
/// Invoked before any children of `expr` are rewritten /
/// visited. Default implementation returns `Ok(RewriteRecursion::Continue)`
fn pre_visit(&mut self, _expr: &Expr) -> Result<RewriteRecursion> {
fn pre_visit(&mut self, _expr: &E) -> Result<RewriteRecursion> {
Ok(RewriteRecursion::Continue)
}

/// Invoked after all children of `expr` have been mutated and
/// returns a potentially modified expr.
fn mutate(&mut self, expr: Expr) -> Result<Expr>;
fn mutate(&mut self, expr: E) -> Result<E>;
}

pub trait ExprRewritable: Sized {
fn rewrite<R: ExprRewriter>(self, rewriter: &mut R) -> Result<Self>;
fn rewrite<R: ExprRewriter<Self>>(self, rewriter: &mut R) -> Result<Self>;
}

impl ExprRewritable for Expr {
Expand Down Expand Up @@ -95,7 +95,7 @@ impl ExprRewritable for Expr {
///
fn rewrite<R>(self, rewriter: &mut R) -> Result<Self>
where
R: ExprRewriter,
R: ExprRewriter<Self>,
{
let need_mutate = match rewriter.pre_visit(&self)? {
RewriteRecursion::Mutate => return rewriter.mutate(self),
Expand Down
12 changes: 7 additions & 5 deletions datafusion/src/logical_plan/expr_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ pub enum Recursion<V: ExpressionVisitor> {
/// `Expr::accept`, `ExpressionVisitor::visit` is invoked
/// recursively on all nodes of an expression tree. See the comments
/// on `Expr::accept` for details on its use
pub trait ExpressionVisitor: Sized {
pub trait ExpressionVisitor<E: ExprVisitable = Expr>: Sized {
/// Invoked before any children of `expr` are visisted.
fn pre_visit(self, expr: &Expr) -> Result<Recursion<Self>>;
fn pre_visit(self, expr: &E) -> Result<Recursion<Self>>
where
Self: ExpressionVisitor;

/// Invoked after all children of `expr` are visited. Default
/// implementation does nothing.
fn post_visit(self, _expr: &Expr) -> Result<Self> {
fn post_visit(self, _expr: &E) -> Result<Self> {
Ok(self)
}
}

pub trait ExprVisitable {
fn accept<V: ExpressionVisitor>(&self, visitor: V) -> Result<V>;
pub trait ExprVisitable: Sized {
fn accept<V: ExpressionVisitor<Self>>(&self, visitor: V) -> Result<V>;
}

impl ExprVisitable for Expr {
Expand Down

0 comments on commit 3768d8c

Please sign in to comment.