From 26f87eaa41272674eb4aaf6aec7492842d48010d Mon Sep 17 00:00:00 2001 From: YuNing Chen Date: Wed, 5 Mar 2025 21:40:48 +0800 Subject: [PATCH] chore: cleanup deprecated API since 40 or earlier --- datafusion/common/src/dfschema.rs | 13 -- .../core/src/execution/session_state.rs | 115 ------------------ .../datasource-parquet/src/file_format.rs | 15 --- datafusion/expr/src/expr.rs | 26 +--- datafusion/expr/src/logical_plan/extension.rs | 18 --- datafusion/expr/src/utils.rs | 10 -- datafusion/optimizer/src/optimizer.rs | 18 --- datafusion/optimizer/src/utils.rs | 38 ------ 8 files changed, 1 insertion(+), 252 deletions(-) diff --git a/datafusion/common/src/dfschema.rs b/datafusion/common/src/dfschema.rs index 99fb179c76a3f..b7101e2bbf406 100644 --- a/datafusion/common/src/dfschema.rs +++ b/datafusion/common/src/dfschema.rs @@ -159,22 +159,9 @@ impl DFSchema { } /// Create a new `DFSchema` from a list of Arrow [Field]s - #[allow(deprecated)] pub fn from_unqualified_fields( fields: Fields, metadata: HashMap, - ) -> Result { - Self::from_unqualifed_fields(fields, metadata) - } - - /// Create a new `DFSchema` from a list of Arrow [Field]s - #[deprecated( - since = "40.0.0", - note = "Please use `from_unqualified_fields` instead (this one's name is a typo). This method is subject to be removed soon" - )] - pub fn from_unqualifed_fields( - fields: Fields, - metadata: HashMap, ) -> Result { let field_count = fields.len(); let schema = Arc::new(Schema::new_with_metadata(fields, metadata)); diff --git a/datafusion/core/src/execution/session_state.rs b/datafusion/core/src/execution/session_state.rs index d26d5a219e183..0e83156ab53f1 100644 --- a/datafusion/core/src/execution/session_state.rs +++ b/datafusion/core/src/execution/session_state.rs @@ -280,22 +280,6 @@ impl SessionState { .build() } - /// Returns new [`SessionState`] using the provided - /// [`SessionConfig`], [`RuntimeEnv`], and [`CatalogProviderList`] - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - pub fn new_with_config_rt_and_catalog_list( - config: SessionConfig, - runtime: Arc, - catalog_list: Arc, - ) -> Self { - SessionStateBuilder::new() - .with_config(config) - .with_runtime_env(runtime) - .with_catalog_list(catalog_list) - .with_default_features() - .build() - } - pub(crate) fn resolve_table_ref( &self, table_ref: impl Into, @@ -334,53 +318,6 @@ impl SessionState { }) } - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Replace the random session id. - pub fn with_session_id(mut self, session_id: String) -> Self { - self.session_id = session_id; - self - } - - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// override default query planner with `query_planner` - pub fn with_query_planner( - mut self, - query_planner: Arc, - ) -> Self { - self.query_planner = query_planner; - self - } - - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Override the [`AnalyzerRule`]s optimizer plan rules. - pub fn with_analyzer_rules( - mut self, - rules: Vec>, - ) -> Self { - self.analyzer = Analyzer::with_rules(rules); - self - } - - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Replace the entire list of [`OptimizerRule`]s used to optimize plans - pub fn with_optimizer_rules( - mut self, - rules: Vec>, - ) -> Self { - self.optimizer = Optimizer::with_rules(rules); - self - } - - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Replace the entire list of [`PhysicalOptimizerRule`]s used to optimize plans - pub fn with_physical_optimizer_rules( - mut self, - physical_optimizers: Vec>, - ) -> Self { - self.physical_optimizers = PhysicalOptimizer::with_rules(physical_optimizers); - self - } - /// Add `analyzer_rule` to the end of the list of /// [`AnalyzerRule`]s used to rewrite queries. pub fn add_analyzer_rule( @@ -391,17 +328,6 @@ impl SessionState { self } - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Add `optimizer_rule` to the end of the list of - /// [`OptimizerRule`]s used to rewrite queries. - pub fn add_optimizer_rule( - mut self, - optimizer_rule: Arc, - ) -> Self { - self.optimizer.rules.push(optimizer_rule); - self - } - // the add_optimizer_rule takes an owned reference // it should probably be renamed to `with_optimizer_rule` to follow builder style // and `add_optimizer_rule` that takes &mut self added instead of this @@ -412,52 +338,11 @@ impl SessionState { self.optimizer.rules.push(optimizer_rule); } - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Add `physical_optimizer_rule` to the end of the list of - /// [`PhysicalOptimizerRule`]s used to rewrite queries. - pub fn add_physical_optimizer_rule( - mut self, - physical_optimizer_rule: Arc, - ) -> Self { - self.physical_optimizers.rules.push(physical_optimizer_rule); - self - } - - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Adds a new [`ConfigExtension`] to TableOptions - pub fn add_table_options_extension( - mut self, - extension: T, - ) -> Self { - self.table_options.extensions.insert(extension); - self - } - - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Registers a [`FunctionFactory`] to handle `CREATE FUNCTION` statements - pub fn with_function_factory( - mut self, - function_factory: Arc, - ) -> Self { - self.function_factory = Some(function_factory); - self - } - /// Registers a [`FunctionFactory`] to handle `CREATE FUNCTION` statements pub fn set_function_factory(&mut self, function_factory: Arc) { self.function_factory = Some(function_factory); } - #[deprecated(since = "40.0.0", note = "Use SessionStateBuilder")] - /// Replace the extension [`SerializerRegistry`] - pub fn with_serializer_registry( - mut self, - registry: Arc, - ) -> Self { - self.serializer_registry = registry; - self - } - /// Get the function factory pub fn function_factory(&self) -> Option<&Arc> { self.function_factory.as_ref() diff --git a/datafusion/datasource-parquet/src/file_format.rs b/datafusion/datasource-parquet/src/file_format.rs index 268bbf4535050..48761d85e7082 100644 --- a/datafusion/datasource-parquet/src/file_format.rs +++ b/datafusion/datasource-parquet/src/file_format.rs @@ -802,21 +802,6 @@ fn get_col_stats( .collect() } -/// Deprecated -/// Use [`statistics_from_parquet_meta_calc`] instead. -/// This method was deprecated because it didn't need to be async so a new method was created -/// that exposes a synchronous API. -#[deprecated( - since = "40.0.0", - note = "please use `statistics_from_parquet_meta_calc` instead" -)] -pub async fn statistics_from_parquet_meta( - metadata: &ParquetMetaData, - table_schema: SchemaRef, -) -> Result { - statistics_from_parquet_meta_calc(metadata, table_schema) -} - fn summarize_min_max_null_counts( min_accs: &mut [Option], max_accs: &mut [Option], diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index 3323ea1614fd9..56279632251b9 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -25,7 +25,6 @@ use std::sync::Arc; use crate::expr_fn::binary_expr; use crate::logical_plan::Subquery; -use crate::utils::expr_to_columns; use crate::Volatility; use crate::{udaf, ExprSchemable, Operator, Signature, WindowFrame, WindowUDF}; @@ -35,7 +34,7 @@ use datafusion_common::tree_node::{ Transformed, TransformedResult, TreeNode, TreeNodeContainer, TreeNodeRecursion, }; use datafusion_common::{ - plan_err, Column, DFSchema, HashMap, Result, ScalarValue, Spans, TableReference, + Column, DFSchema, HashMap, Result, ScalarValue, Spans, TableReference, }; use datafusion_functions_window_common::field::WindowUDFFieldArgs; use sqlparser::ast::{ @@ -1090,11 +1089,6 @@ impl PlannedReplaceSelectItem { } impl Expr { - #[deprecated(since = "40.0.0", note = "use schema_name instead")] - pub fn display_name(&self) -> Result { - Ok(self.schema_name().to_string()) - } - /// The name of the column (field) that this `Expr` will produce. /// /// For example, for a projection (e.g. `SELECT `) the resulting arrow @@ -1444,15 +1438,6 @@ impl Expr { Box::new(high), )) } - - #[deprecated(since = "39.0.0", note = "use try_as_col instead")] - pub fn try_into_col(&self) -> Result { - match self { - Expr::Column(it) => Ok(it.clone()), - _ => plan_err!("Could not coerce '{self}' into Column!"), - } - } - /// Return a reference to the inner `Column` if any /// /// returns `None` if the expression is not a `Column` @@ -1495,15 +1480,6 @@ impl Expr { } } - /// Return all referenced columns of this expression. - #[deprecated(since = "40.0.0", note = "use Expr::column_refs instead")] - pub fn to_columns(&self) -> Result> { - let mut using_columns = HashSet::new(); - expr_to_columns(self, &mut using_columns)?; - - Ok(using_columns) - } - /// Return all references to columns in this expression. /// /// # Example diff --git a/datafusion/expr/src/logical_plan/extension.rs b/datafusion/expr/src/logical_plan/extension.rs index be7153cc4eaa3..5bf64a36a6540 100644 --- a/datafusion/expr/src/logical_plan/extension.rs +++ b/datafusion/expr/src/logical_plan/extension.rs @@ -82,17 +82,6 @@ pub trait UserDefinedLogicalNode: fmt::Debug + Send + Sync { /// For example: `TopK: k=10` fn fmt_for_explain(&self, f: &mut fmt::Formatter) -> fmt::Result; - #[deprecated(since = "39.0.0", note = "use with_exprs_and_inputs instead")] - #[allow(clippy::wrong_self_convention)] - fn from_template( - &self, - exprs: &[Expr], - inputs: &[LogicalPlan], - ) -> Arc { - self.with_exprs_and_inputs(exprs.to_vec(), inputs.to_vec()) - .unwrap() - } - /// Create a new `UserDefinedLogicalNode` with the specified children /// and expressions. This function is used during optimization /// when the plan is being rewritten and a new instance of the @@ -282,13 +271,6 @@ pub trait UserDefinedLogicalNodeCore: /// For example: `TopK: k=10` fn fmt_for_explain(&self, f: &mut fmt::Formatter) -> fmt::Result; - #[deprecated(since = "39.0.0", note = "use with_exprs_and_inputs instead")] - #[allow(clippy::wrong_self_convention)] - fn from_template(&self, exprs: &[Expr], inputs: &[LogicalPlan]) -> Self { - self.with_exprs_and_inputs(exprs.to_vec(), inputs.to_vec()) - .unwrap() - } - /// Create a new `UserDefinedLogicalNode` with the specified children /// and expressions. This function is used during optimization /// when the plan is being rewritten and a new instance of the diff --git a/datafusion/expr/src/utils.rs b/datafusion/expr/src/utils.rs index 3846566e27fec..3404cce171883 100644 --- a/datafusion/expr/src/utils.rs +++ b/datafusion/expr/src/utils.rs @@ -48,16 +48,6 @@ pub use datafusion_functions_aggregate_common::order::AggregateOrderSensitivity; /// `COUNT()` expressions pub use datafusion_common::utils::expr::COUNT_STAR_EXPANSION; -/// Recursively walk a list of expression trees, collecting the unique set of columns -/// referenced in the expression -#[deprecated(since = "40.0.0", note = "Expr::add_column_refs instead")] -pub fn exprlist_to_columns(expr: &[Expr], accum: &mut HashSet) -> Result<()> { - for e in expr { - expr_to_columns(e, accum)?; - } - Ok(()) -} - /// Count the number of distinct exprs in a list of group by expressions. If the /// first element is a `GroupingSet` expression then it must be the only expr. pub fn grouping_set_expr_count(group_expr: &[Expr]) -> Result { diff --git a/datafusion/optimizer/src/optimizer.rs b/datafusion/optimizer/src/optimizer.rs index 49bce3c1ce82c..02457fa250c3d 100644 --- a/datafusion/optimizer/src/optimizer.rs +++ b/datafusion/optimizer/src/optimizer.rs @@ -70,24 +70,6 @@ use crate::utils::log_plan; /// [`AnalyzerRule`]: crate::analyzer::AnalyzerRule /// [`SessionState::add_optimizer_rule`]: https://docs.rs/datafusion/latest/datafusion/execution/session_state/struct.SessionState.html#method.add_optimizer_rule pub trait OptimizerRule: Debug { - /// Try and rewrite `plan` to an optimized form, returning None if the plan - /// cannot be optimized by this rule. - /// - /// Note this API will be deprecated in the future as it requires `clone`ing - /// the input plan, which can be expensive. OptimizerRules should implement - /// [`Self::rewrite`] instead. - #[deprecated( - since = "40.0.0", - note = "please implement supports_rewrite and rewrite instead" - )] - fn try_optimize( - &self, - _plan: &LogicalPlan, - _config: &dyn OptimizerConfig, - ) -> Result> { - internal_err!("Should have called rewrite") - } - /// A human readable name for this optimizer rule fn name(&self) -> &str; diff --git a/datafusion/optimizer/src/utils.rs b/datafusion/optimizer/src/utils.rs index 39f8cf285d17c..262e51a7e26db 100644 --- a/datafusion/optimizer/src/utils.rs +++ b/datafusion/optimizer/src/utils.rs @@ -38,44 +38,6 @@ use std::sync::Arc; /// as it was initially placed here and then moved elsewhere. pub use datafusion_expr::expr_rewriter::NamePreserver; -/// Convenience rule for writing optimizers: recursively invoke -/// optimize on plan's children and then return a node of the same -/// type. Useful for optimizer rules which want to leave the type -/// of plan unchanged but still apply to the children. -/// This also handles the case when the `plan` is a [`LogicalPlan::Explain`]. -/// -/// Returning `Ok(None)` indicates that the plan can't be optimized by the `optimizer`. -#[deprecated( - since = "40.0.0", - note = "please use OptimizerRule::apply_order with ApplyOrder::BottomUp instead" -)] -pub fn optimize_children( - optimizer: &impl OptimizerRule, - plan: &LogicalPlan, - config: &dyn OptimizerConfig, -) -> Result> { - let mut new_inputs = Vec::with_capacity(plan.inputs().len()); - let mut plan_is_changed = false; - for input in plan.inputs() { - if optimizer.supports_rewrite() { - let new_input = optimizer.rewrite(input.clone(), config)?; - plan_is_changed = plan_is_changed || new_input.transformed; - new_inputs.push(new_input.data); - } else { - #[allow(deprecated)] - let new_input = optimizer.try_optimize(input, config)?; - plan_is_changed = plan_is_changed || new_input.is_some(); - new_inputs.push(new_input.unwrap_or_else(|| input.clone())) - } - } - if plan_is_changed { - let exprs = plan.expressions(); - plan.with_new_exprs(exprs, new_inputs).map(Some) - } else { - Ok(None) - } -} - /// Returns true if `expr` contains all columns in `schema_cols` pub(crate) fn has_all_column_refs(expr: &Expr, schema_cols: &HashSet) -> bool { let column_refs = expr.column_refs();