diff --git a/datafusion/expr/src/expr_rewriter/mod.rs b/datafusion/expr/src/expr_rewriter/mod.rs index cb7b124f91927..18fb495b73884 100644 --- a/datafusion/expr/src/expr_rewriter/mod.rs +++ b/datafusion/expr/src/expr_rewriter/mod.rs @@ -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; @@ -250,10 +250,10 @@ pub fn unalias(expr: Expr) -> Expr { /// schema of plan nodes don't change after optimization pub fn rewrite_preserving_name(expr: Expr, rewriter: &mut R) -> Result where - R: TreeNodeRewriter, + R: TreeNodeRewriterOld, { let original_name = expr.name_for_alias()?; - let expr = expr.rewrite(rewriter)?; + let expr = expr.rewrite_old(rewriter)?; expr.alias_if_changed(original_name) } diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs index 3bf700e5e430d..3f5a0608efdc0 100644 --- a/datafusion/expr/src/logical_plan/plan.rs +++ b/datafusion/expr/src/logical_plan/plan.rs @@ -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, diff --git a/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs b/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs index bed7d6cc777dc..e17a7c5d82d9d 100644 --- a/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs +++ b/datafusion/optimizer/src/analyzer/count_wildcard_rule.rs @@ -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; @@ -113,10 +113,10 @@ fn analyze_internal(plan: LogicalPlan) -> Result { 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 { + fn mutate(&mut self, old_expr: Expr) -> Result { let new_expr = match old_expr.clone() { Expr::WindowFunction(expr::WindowFunction { fun: diff --git a/datafusion/optimizer/src/analyzer/rewrite_expr.rs b/datafusion/optimizer/src/analyzer/rewrite_expr.rs index 829197b4d9481..6e0ca40c99f53 100644 --- a/datafusion/optimizer/src/analyzer/rewrite_expr.rs +++ b/datafusion/optimizer/src/analyzer/rewrite_expr.rs @@ -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; @@ -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 { + fn mutate(&mut self, expr: Expr) -> Result { match expr { Expr::BinaryExpr(BinaryExpr { ref left, diff --git a/datafusion/optimizer/src/analyzer/type_coercion.rs b/datafusion/optimizer/src/analyzer/type_coercion.rs index 0e71d23ac27fa..f1b6d151f50ec 100644 --- a/datafusion/optimizer/src/analyzer/type_coercion.rs +++ b/datafusion/optimizer/src/analyzer/type_coercion.rs @@ -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, @@ -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 { + fn pre_visit(&mut self, _expr: &Expr) -> Result { + Ok(RewriteRecursion::Continue) + } + + fn mutate(&mut self, expr: Expr) -> Result { match expr { Expr::ScalarSubquery(Subquery { subquery, @@ -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( @@ -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 @@ -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 @@ -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(()) diff --git a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs index 2d5b88bcb4a59..f0ec6a361b398 100644 --- a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs +++ b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs @@ -162,7 +162,7 @@ impl ExprSimplifier { pub fn coerce(&self, expr: Expr, schema: DFSchemaRef) -> Result { let mut expr_rewrite = TypeCoercionRewriter { schema }; - expr.rewrite(&mut expr_rewrite) + expr.rewrite_old(&mut expr_rewrite) } /// Input guarantees about the values of columns. diff --git a/datafusion/optimizer/src/simplify_expressions/guarantees.rs b/datafusion/optimizer/src/simplify_expressions/guarantees.rs index 6ecebf136adce..6cd1aa9e578eb 100644 --- a/datafusion/optimizer/src/simplify_expressions/guarantees.rs +++ b/datafusion/optimizer/src/simplify_expressions/guarantees.rs @@ -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}; diff --git a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs index 0232a28c722a6..38c154768737f 100644 --- a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs +++ b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs @@ -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, }; @@ -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 { + fn pre_visit(&mut self, _expr: &Expr) -> Result { + Ok(RewriteRecursion::Continue) + } + + fn mutate(&mut self, expr: Expr) -> Result { match &expr { // For case: // try_cast/cast(expr as data_type) op literal @@ -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 {