Skip to content

Commit

Permalink
revert7
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-toth committed Jan 12, 2024
1 parent d4764ee commit 9b20456
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
expr.rewrite(&mut const_evaluator)?
.rewrite(&mut simplifier)?
.rewrite(&mut or_in_list_simplifier)?
.rewrite(&mut guarantee_rewriter)?
.rewrite_old(&mut guarantee_rewriter)?
// run both passes twice to try an minimize simplifications that we missed
.rewrite(&mut const_evaluator)?
.rewrite(&mut simplifier)
Expand Down
21 changes: 11 additions & 10 deletions datafusion/optimizer/src/simplify_expressions/guarantees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
use std::{borrow::Cow, collections::HashMap};

use datafusion_common::{tree_node::TreeNodeRewriter, DataFusionError, Result};
use datafusion_common::{DataFusionError, Result};
use datafusion_common::tree_node::TreeNodeRewriterOld;
use datafusion_expr::interval_arithmetic::{Interval, NullableInterval};
use datafusion_expr::{expr::InList, lit, Between, BinaryExpr, Expr};

Expand Down Expand Up @@ -56,10 +57,10 @@ impl<'a> GuaranteeRewriter<'a> {
}
}

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

fn f_up(&mut self, expr: Expr) -> Result<Expr> {
fn mutate(&mut self, expr: Expr) -> Result<Expr> {
if self.guarantees.is_empty() {
return Ok(expr);
}
Expand Down Expand Up @@ -221,12 +222,12 @@ mod tests {

// x IS NULL => guaranteed false
let expr = col("x").is_null();
let output = expr.clone().rewrite(&mut rewriter).unwrap();
let output = expr.clone().rewrite_old(&mut rewriter).unwrap();
assert_eq!(output, lit(false));

// x IS NOT NULL => guaranteed true
let expr = col("x").is_not_null();
let output = expr.clone().rewrite(&mut rewriter).unwrap();
let output = expr.clone().rewrite_old(&mut rewriter).unwrap();
assert_eq!(output, lit(true));
}

Expand All @@ -236,7 +237,7 @@ mod tests {
T: Clone,
{
for (expr, expected_value) in cases {
let output = expr.clone().rewrite(rewriter).unwrap();
let output = expr.clone().rewrite_old(rewriter).unwrap();
let expected = lit(ScalarValue::from(expected_value.clone()));
assert_eq!(
output, expected,
Expand All @@ -248,7 +249,7 @@ mod tests {

fn validate_unchanged_cases(rewriter: &mut GuaranteeRewriter, cases: &[Expr]) {
for expr in cases {
let output = expr.clone().rewrite(rewriter).unwrap();
let output = expr.clone().rewrite_old(rewriter).unwrap();
assert_eq!(
&output, expr,
"{} was simplified to {}, but expected it to be unchanged",
Expand Down Expand Up @@ -478,7 +479,7 @@ mod tests {
let guarantees = vec![(col("x"), NullableInterval::from(scalar.clone()))];
let mut rewriter = GuaranteeRewriter::new(guarantees.iter());

let output = col("x").rewrite(&mut rewriter).unwrap();
let output = col("x").rewrite_old(&mut rewriter).unwrap();
assert_eq!(output, Expr::Literal(scalar.clone()));
}
}
Expand Down Expand Up @@ -522,7 +523,7 @@ mod tests {
.collect(),
*negated,
);
let output = expr.clone().rewrite(&mut rewriter).unwrap();
let output = expr.clone().rewrite_old(&mut rewriter).unwrap();
let expected_list = expected_list
.iter()
.map(|v| lit(ScalarValue::Int32(Some(*v))))
Expand Down

0 comments on commit 9b20456

Please sign in to comment.