Skip to content

Commit 1fd44f2

Browse files
committed
chore: cleanup deprecated optimizer API since version <= 40
follow up of #15027
1 parent 05bb569 commit 1fd44f2

File tree

4 files changed

+5
-75
lines changed

4 files changed

+5
-75
lines changed

datafusion/optimizer/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ pub use analyzer::{Analyzer, AnalyzerRule};
6969
pub use optimizer::{
7070
ApplyOrder, Optimizer, OptimizerConfig, OptimizerContext, OptimizerRule,
7171
};
72-
#[allow(deprecated)]
73-
pub use utils::optimize_children;
7472

7573
pub(crate) mod join_key_set;
7674
mod plan_signature;

datafusion/optimizer/src/optimizer.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,6 @@ use crate::utils::log_plan;
6969
/// [`AnalyzerRule`]: crate::analyzer::AnalyzerRule
7070
/// [`SessionState::add_optimizer_rule`]: https://docs.rs/datafusion/latest/datafusion/execution/session_state/struct.SessionState.html#method.add_optimizer_rule
7171
pub trait OptimizerRule: Debug {
72-
/// Try and rewrite `plan` to an optimized form, returning None if the plan
73-
/// cannot be optimized by this rule.
74-
///
75-
/// Note this API will be deprecated in the future as it requires `clone`ing
76-
/// the input plan, which can be expensive. OptimizerRules should implement
77-
/// [`Self::rewrite`] instead.
78-
#[deprecated(
79-
since = "40.0.0",
80-
note = "please implement supports_rewrite and rewrite instead"
81-
)]
82-
fn try_optimize(
83-
&self,
84-
_plan: &LogicalPlan,
85-
_config: &dyn OptimizerConfig,
86-
) -> Result<Option<LogicalPlan>> {
87-
internal_err!("Should have called rewrite")
88-
}
89-
9072
/// A human readable name for this optimizer rule
9173
fn name(&self) -> &str;
9274

@@ -107,7 +89,7 @@ pub trait OptimizerRule: Debug {
10789
/// if the plan was rewritten and `Transformed::no` if it was not.
10890
///
10991
/// Note: this function is only called if [`Self::supports_rewrite`] returns
110-
/// true. Otherwise the Optimizer calls [`Self::try_optimize`]
92+
/// true.
11193
fn rewrite(
11294
&self,
11395
_plan: LogicalPlan,
@@ -326,19 +308,10 @@ fn optimize_plan_node(
326308
config: &dyn OptimizerConfig,
327309
) -> Result<Transformed<LogicalPlan>> {
328310
if rule.supports_rewrite() {
329-
return rule.rewrite(plan, config);
311+
rule.rewrite(plan, config)
312+
} else {
313+
Ok(Transformed::no(plan))
330314
}
331-
332-
#[allow(deprecated)]
333-
rule.try_optimize(&plan, config).map(|maybe_plan| {
334-
match maybe_plan {
335-
Some(new_plan) => {
336-
// if the node was rewritten by the optimizer, replace the node
337-
Transformed::yes(new_plan)
338-
}
339-
None => Transformed::no(plan),
340-
}
341-
})
342315
}
343316

344317
impl Optimizer {

datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ impl OptimizerRule for SimplifyExpressions {
6262
true
6363
}
6464

65-
/// if supports_owned returns true, the Optimizer calls
66-
/// [`Self::rewrite`] instead of [`Self::try_optimize`]
65+
/// if supports_owned returns true, the Optimizer calls [`Self::rewrite`]
6766
fn rewrite(
6867
&self,
6968
plan: LogicalPlan,

datafusion/optimizer/src/utils.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
2020
use std::collections::{BTreeSet, HashMap, HashSet};
2121

22-
use crate::{OptimizerConfig, OptimizerRule};
23-
2422
use crate::analyzer::type_coercion::TypeCoercionRewriter;
2523
use arrow::array::{new_null_array, Array, RecordBatch};
2624
use arrow::datatypes::{DataType, Field, Schema};
@@ -38,44 +36,6 @@ use std::sync::Arc;
3836
/// as it was initially placed here and then moved elsewhere.
3937
pub use datafusion_expr::expr_rewriter::NamePreserver;
4038

41-
/// Convenience rule for writing optimizers: recursively invoke
42-
/// optimize on plan's children and then return a node of the same
43-
/// type. Useful for optimizer rules which want to leave the type
44-
/// of plan unchanged but still apply to the children.
45-
/// This also handles the case when the `plan` is a [`LogicalPlan::Explain`].
46-
///
47-
/// Returning `Ok(None)` indicates that the plan can't be optimized by the `optimizer`.
48-
#[deprecated(
49-
since = "40.0.0",
50-
note = "please use OptimizerRule::apply_order with ApplyOrder::BottomUp instead"
51-
)]
52-
pub fn optimize_children(
53-
optimizer: &impl OptimizerRule,
54-
plan: &LogicalPlan,
55-
config: &dyn OptimizerConfig,
56-
) -> Result<Option<LogicalPlan>> {
57-
let mut new_inputs = Vec::with_capacity(plan.inputs().len());
58-
let mut plan_is_changed = false;
59-
for input in plan.inputs() {
60-
if optimizer.supports_rewrite() {
61-
let new_input = optimizer.rewrite(input.clone(), config)?;
62-
plan_is_changed = plan_is_changed || new_input.transformed;
63-
new_inputs.push(new_input.data);
64-
} else {
65-
#[allow(deprecated)]
66-
let new_input = optimizer.try_optimize(input, config)?;
67-
plan_is_changed = plan_is_changed || new_input.is_some();
68-
new_inputs.push(new_input.unwrap_or_else(|| input.clone()))
69-
}
70-
}
71-
if plan_is_changed {
72-
let exprs = plan.expressions();
73-
plan.with_new_exprs(exprs, new_inputs).map(Some)
74-
} else {
75-
Ok(None)
76-
}
77-
}
78-
7939
/// Returns true if `expr` contains all columns in `schema_cols`
8040
pub(crate) fn has_all_column_refs(expr: &Expr, schema_cols: &HashSet<Column>) -> bool {
8141
let column_refs = expr.column_refs();

0 commit comments

Comments
 (0)