Skip to content

Commit

Permalink
revert8
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-toth committed Jan 12, 2024
1 parent 9b20456 commit a616abd
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 27 deletions.
6 changes: 3 additions & 3 deletions datafusion/expr/src/expr_rewriter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use crate::expr::Alias;
use crate::logical_plan::Projection;
use crate::{Expr, ExprSchemable, LogicalPlan, LogicalPlanBuilder};
use datafusion_common::tree_node::{TreeNode, TreeNodeRewriter};
use datafusion_common::tree_node::{TreeNode, TreeNodeRewriterOld};
use datafusion_common::Result;
use datafusion_common::{Column, DFSchema};
use std::collections::HashMap;
Expand Down Expand Up @@ -250,10 +250,10 @@ pub fn unalias(expr: Expr) -> Expr {
/// schema of plan nodes don't change after optimization
pub fn rewrite_preserving_name<R>(expr: Expr, rewriter: &mut R) -> Result<Expr>
where
R: TreeNodeRewriter<Node = Expr>,
R: TreeNodeRewriterOld<N = Expr>,
{
let original_name = expr.name_for_alias()?;
let expr = expr.rewrite(rewriter)?;
let expr = expr.rewrite_old(rewriter)?;
expr.alias_if_changed(original_name)
}

Expand Down
4 changes: 3 additions & 1 deletion datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ use crate::{
};

use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
use datafusion_common::tree_node::{RewriteRecursion, TreeNode, TreeNodeRecursion, TreeNodeRewriterOld, TreeNodeVisitor};
use datafusion_common::tree_node::{
RewriteRecursion, TreeNode, TreeNodeRecursion, TreeNodeRewriterOld, TreeNodeVisitor,
};
use datafusion_common::{
aggregate_functional_dependencies, internal_err, plan_err, Column, Constraints,
DFField, DFSchema, DFSchemaRef, DataFusionError, Dependency, FunctionalDependence,
Expand Down
8 changes: 4 additions & 4 deletions datafusion/optimizer/src/analyzer/count_wildcard_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::analyzer::AnalyzerRule;
use datafusion_common::config::ConfigOptions;
use datafusion_common::tree_node::{TreeNode, TreeNodeRewriter};
use datafusion_common::tree_node::{TreeNode, TreeNodeRewriterOld};
use datafusion_common::Result;
use datafusion_expr::expr::{AggregateFunction, AggregateFunctionDefinition, InSubquery};
use datafusion_expr::expr_rewriter::rewrite_preserving_name;
Expand Down Expand Up @@ -113,10 +113,10 @@ fn analyze_internal(plan: LogicalPlan) -> Result<LogicalPlan> {

struct CountWildcardRewriter {}

impl TreeNodeRewriter for CountWildcardRewriter {
type Node = Expr;
impl TreeNodeRewriterOld for CountWildcardRewriter {
type N = Expr;

fn f_up(&mut self, old_expr: Expr) -> Result<Expr> {
fn mutate(&mut self, old_expr: Expr) -> Result<Expr> {
let new_expr = match old_expr.clone() {
Expr::WindowFunction(expr::WindowFunction {
fun:
Expand Down
8 changes: 4 additions & 4 deletions datafusion/optimizer/src/analyzer/rewrite_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::sync::Arc;

use datafusion_common::config::ConfigOptions;
use datafusion_common::tree_node::TreeNodeRewriter;
use datafusion_common::tree_node::TreeNodeRewriterOld;
use datafusion_common::utils::list_ndims;
use datafusion_common::DFSchema;
use datafusion_common::DFSchemaRef;
Expand Down Expand Up @@ -93,10 +93,10 @@ pub(crate) struct OperatorToFunctionRewriter {
pub(crate) schema: DFSchemaRef,
}

impl TreeNodeRewriter for OperatorToFunctionRewriter {
type Node = Expr;
impl TreeNodeRewriterOld for OperatorToFunctionRewriter {
type N = Expr;

fn f_up(&mut self, expr: Expr) -> Result<Expr> {
fn mutate(&mut self, expr: Expr) -> Result<Expr> {
match expr {
Expr::BinaryExpr(BinaryExpr {
ref left,
Expand Down
20 changes: 12 additions & 8 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::sync::Arc;
use arrow::datatypes::{DataType, IntervalUnit};

use datafusion_common::config::ConfigOptions;
use datafusion_common::tree_node::TreeNodeRewriter;
use datafusion_common::tree_node::{RewriteRecursion, TreeNodeRewriterOld};
use datafusion_common::{
exec_err, internal_err, plan_datafusion_err, plan_err, DFSchema, DFSchemaRef,
DataFusionError, Result, ScalarValue,
Expand Down Expand Up @@ -125,10 +125,14 @@ pub(crate) struct TypeCoercionRewriter {
pub(crate) schema: DFSchemaRef,
}

impl TreeNodeRewriter for TypeCoercionRewriter {
type Node = Expr;
impl TreeNodeRewriterOld for TypeCoercionRewriter {
type N = Expr;

fn f_up(&mut self, expr: Expr) -> Result<Expr> {
fn pre_visit(&mut self, _expr: &Expr) -> Result<RewriteRecursion> {
Ok(RewriteRecursion::Continue)
}

fn mutate(&mut self, expr: Expr) -> Result<Expr> {
match expr {
Expr::ScalarSubquery(Subquery {
subquery,
Expand Down Expand Up @@ -1240,7 +1244,7 @@ mod test {
std::collections::HashMap::new(),
)?);
let mut rewriter = TypeCoercionRewriter { schema };
let result = expr.rewrite(&mut rewriter)?;
let result = expr.rewrite_old(&mut rewriter)?;

let schema = Arc::new(DFSchema::new_with_metadata(
vec![DFField::new_unqualified(
Expand Down Expand Up @@ -1275,7 +1279,7 @@ mod test {
let mut rewriter = TypeCoercionRewriter { schema };
let expr = is_true(lit(12i32).gt(lit(13i64)));
let expected = is_true(cast(lit(12i32), DataType::Int64).gt(lit(13i64)));
let result = expr.rewrite(&mut rewriter)?;
let result = expr.rewrite_old(&mut rewriter)?;
assert_eq!(expected, result);

// eq
Expand All @@ -1286,7 +1290,7 @@ mod test {
let mut rewriter = TypeCoercionRewriter { schema };
let expr = is_true(lit(12i32).eq(lit(13i64)));
let expected = is_true(cast(lit(12i32), DataType::Int64).eq(lit(13i64)));
let result = expr.rewrite(&mut rewriter)?;
let result = expr.rewrite_old(&mut rewriter)?;
assert_eq!(expected, result);

// lt
Expand All @@ -1297,7 +1301,7 @@ mod test {
let mut rewriter = TypeCoercionRewriter { schema };
let expr = is_true(lit(12i32).lt(lit(13i64)));
let expected = is_true(cast(lit(12i32), DataType::Int64).lt(lit(13i64)));
let result = expr.rewrite(&mut rewriter)?;
let result = expr.rewrite_old(&mut rewriter)?;
assert_eq!(expected, result);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
pub fn coerce(&self, expr: Expr, schema: DFSchemaRef) -> Result<Expr> {
let mut expr_rewrite = TypeCoercionRewriter { schema };

expr.rewrite(&mut expr_rewrite)
expr.rewrite_old(&mut expr_rewrite)
}

/// Input guarantees about the values of columns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
use std::{borrow::Cow, collections::HashMap};

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

Expand Down
14 changes: 9 additions & 5 deletions datafusion/optimizer/src/unwrap_cast_in_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use arrow::datatypes::{
DataType, TimeUnit, MAX_DECIMAL_FOR_EACH_PRECISION, MIN_DECIMAL_FOR_EACH_PRECISION,
};
use arrow::temporal_conversions::{MICROSECONDS, MILLISECONDS, NANOSECONDS};
use datafusion_common::tree_node::TreeNodeRewriter;
use datafusion_common::tree_node::{RewriteRecursion, TreeNodeRewriterOld};
use datafusion_common::{
internal_err, DFSchema, DFSchemaRef, DataFusionError, Result, ScalarValue,
};
Expand Down Expand Up @@ -126,10 +126,14 @@ struct UnwrapCastExprRewriter {
schema: DFSchemaRef,
}

impl TreeNodeRewriter for UnwrapCastExprRewriter {
type Node = Expr;
impl TreeNodeRewriterOld for UnwrapCastExprRewriter {
type N = Expr;

fn f_up(&mut self, expr: Expr) -> Result<Expr> {
fn pre_visit(&mut self, _expr: &Expr) -> Result<RewriteRecursion> {
Ok(RewriteRecursion::Continue)
}

fn mutate(&mut self, expr: Expr) -> Result<Expr> {
match &expr {
// For case:
// try_cast/cast(expr as data_type) op literal
Expand Down Expand Up @@ -730,7 +734,7 @@ mod tests {
let mut expr_rewriter = UnwrapCastExprRewriter {
schema: schema.clone(),
};
expr.rewrite(&mut expr_rewriter).unwrap()
expr.rewrite_old(&mut expr_rewriter).unwrap()
}

fn expr_test_schema() -> DFSchemaRef {
Expand Down

0 comments on commit a616abd

Please sign in to comment.