Skip to content

Commit

Permalink
Jump doesn't ignore f_up
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasrepo committed Feb 27, 2024
1 parent f079fce commit 988dd28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 10 additions & 3 deletions datafusion/common/src/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,16 @@ pub trait TreeNode: Sized {
&self,
visitor: &mut V,
) -> Result<TreeNodeRecursion> {
handle_visit_recursion_down!(visitor.f_down(self)?);
handle_visit_recursion_up!(self.apply_children(&mut |n| n.visit(visitor))?);
visitor.f_up(self)
match visitor.f_down(self)? {
TreeNodeRecursion::Continue => {
handle_visit_recursion_up!(
self.apply_children(&mut |n| n.visit(visitor))?
);
visitor.f_up(self)
}
TreeNodeRecursion::Jump => visitor.f_up(self),
TreeNodeRecursion::Stop => Ok(TreeNodeRecursion::Stop),
}
}

/// Implements the [visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) for
Expand Down
14 changes: 9 additions & 5 deletions datafusion/optimizer/src/common_subexpr_eliminate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,21 +642,20 @@ impl ExprIdentifierVisitor<'_> {

/// Find the first `EnterMark` in the stack, and accumulates every `ExprItem`
/// before it.
fn pop_enter_mark(&mut self) -> (usize, Identifier) {
fn pop_enter_mark(&mut self) -> Option<(usize, Identifier)> {
let mut desc = String::new();

while let Some(item) = self.visit_stack.pop() {
match item {
VisitRecord::EnterMark(idx) => {
return (idx, desc);
return Some((idx, desc));
}
VisitRecord::ExprItem(s) => {
desc.push_str(&s);
}
}
}

unreachable!("Enter mark should paired with node number");
None
}
}

Expand All @@ -680,7 +679,12 @@ impl TreeNodeVisitor for ExprIdentifierVisitor<'_> {
fn f_up(&mut self, expr: &Expr) -> Result<TreeNodeRecursion> {
self.series_number += 1;

let (idx, sub_expr_desc) = self.pop_enter_mark();
let (idx, sub_expr_desc) =
if let Some((idx, sub_expr_desc)) = self.pop_enter_mark() {
(idx, sub_expr_desc)
} else {
return Ok(TreeNodeRecursion::Continue);
};
// skip exprs should not be recognize.
if self.expr_mask.ignores(expr) {
self.id_array[idx].0 = self.series_number;
Expand Down

0 comments on commit 988dd28

Please sign in to comment.