Skip to content

Commit

Permalink
revert9
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-toth committed Jan 12, 2024
1 parent d3b87b8 commit 8162e02
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use arrow::{
datatypes::{DataType, Field, Schema},
record_batch::RecordBatch,
};
use datafusion_common::tree_node::TreeNodeRecursion;
use datafusion_common::tree_node::{RewriteRecursion, TreeNodeRewriterOld};
use datafusion_common::{
cast::{as_large_list_array, as_list_array},
plan_err,
Expand Down Expand Up @@ -140,12 +140,12 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
// (evaluating constants can enable new simplifications and
// simplifications can enable new constant evaluation)
// https://github.com/apache/arrow-datafusion/issues/1160
expr.rewrite(&mut const_evaluator)?
expr.rewrite_old(&mut const_evaluator)?
.rewrite(&mut simplifier)?
.rewrite(&mut or_in_list_simplifier)?
.rewrite_old(&mut guarantee_rewriter)?
// run both passes twice to try an minimize simplifications that we missed
.rewrite(&mut const_evaluator)?
.rewrite_old(&mut const_evaluator)?
.rewrite(&mut simplifier)
}

Expand Down Expand Up @@ -250,18 +250,18 @@ struct ConstEvaluator<'a> {
input_batch: RecordBatch,
}

impl<'a> TreeNodeRewriter for ConstEvaluator<'a> {
type Node = Expr;
impl<'a> TreeNodeRewriterOld for ConstEvaluator<'a> {
type N = Expr;

fn f_down(&mut self, expr: Expr) -> Result<(Expr, TreeNodeRecursion)> {
fn pre_visit(&mut self, expr: &Expr) -> Result<RewriteRecursion> {
// Default to being able to evaluate this node
self.can_evaluate.push(true);

// if this expr is not ok to evaluate, mark entire parent
// stack as not ok (as all parents have at least one child or
// descendant that can not be evaluated

if !Self::can_evaluate(&expr) {
if !Self::can_evaluate(expr) {
// walk back up stack, marking first parent that is not mutable
let parent_iter = self.can_evaluate.iter_mut().rev();
for p in parent_iter {
Expand All @@ -277,10 +277,10 @@ impl<'a> TreeNodeRewriter for ConstEvaluator<'a> {
// NB: do not short circuit recursion even if we find a non
// evaluatable node (so we can fold other children, args to
// functions, etc)
Ok((expr, TreeNodeRecursion::Continue))
Ok(RewriteRecursion::Continue)
}

fn f_up(&mut self, expr: Expr) -> Result<Expr> {
fn mutate(&mut self, expr: Expr) -> Result<Expr> {
match self.can_evaluate.pop() {
Some(true) => Ok(Expr::Literal(self.evaluate_to_scalar(expr)?)),
Some(false) => Ok(expr),
Expand Down Expand Up @@ -1425,7 +1425,7 @@ mod tests {
let mut const_evaluator = ConstEvaluator::try_new(&execution_props).unwrap();
let evaluated_expr = input_expr
.clone()
.rewrite(&mut const_evaluator)
.rewrite_old(&mut const_evaluator)
.expect("successfully evaluated");

assert_eq!(
Expand Down

0 comments on commit 8162e02

Please sign in to comment.