From aab40e15de1d248db584cb9a2426d5f4282ad85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9E=97=E4=BC=9F?= Date: Wed, 22 May 2024 00:21:23 +0800 Subject: [PATCH] Improve ContextProvider (#10577) --- datafusion-examples/examples/rewrite_expr.rs | 6 +++--- datafusion/core/src/execution/context/mod.rs | 6 +++--- datafusion/core/tests/optimizer_integration.rs | 6 +++--- .../optimizer/tests/optimizer_integration.rs | 6 +++--- datafusion/sql/examples/sql.rs | 6 +++--- datafusion/sql/src/expr/function.rs | 8 ++++---- datafusion/sql/src/expr/mod.rs | 6 +++--- datafusion/sql/src/planner.rs | 15 ++++++++------- datafusion/sql/tests/sql_integration.rs | 6 +++--- 9 files changed, 33 insertions(+), 32 deletions(-) diff --git a/datafusion-examples/examples/rewrite_expr.rs b/datafusion-examples/examples/rewrite_expr.rs index 4943fee444d5..d8965888eab6 100644 --- a/datafusion-examples/examples/rewrite_expr.rs +++ b/datafusion-examples/examples/rewrite_expr.rs @@ -227,15 +227,15 @@ impl ContextProvider for MyContextProvider { &self.options } - fn udfs_names(&self) -> Vec { + fn udf_names(&self) -> Vec { Vec::new() } - fn udafs_names(&self) -> Vec { + fn udaf_names(&self) -> Vec { Vec::new() } - fn udwfs_names(&self) -> Vec { + fn udwf_names(&self) -> Vec { Vec::new() } } diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs index 2fc1a19c3386..59238ffc559a 100644 --- a/datafusion/core/src/execution/context/mod.rs +++ b/datafusion/core/src/execution/context/mod.rs @@ -2209,15 +2209,15 @@ impl<'a> ContextProvider for SessionContextProvider<'a> { self.state.config_options() } - fn udfs_names(&self) -> Vec { + fn udf_names(&self) -> Vec { self.state.scalar_functions().keys().cloned().collect() } - fn udafs_names(&self) -> Vec { + fn udaf_names(&self) -> Vec { self.state.aggregate_functions().keys().cloned().collect() } - fn udwfs_names(&self) -> Vec { + fn udwf_names(&self) -> Vec { self.state.window_functions().keys().cloned().collect() } } diff --git a/datafusion/core/tests/optimizer_integration.rs b/datafusion/core/tests/optimizer_integration.rs index f84e8e24af78..39f745cd3309 100644 --- a/datafusion/core/tests/optimizer_integration.rs +++ b/datafusion/core/tests/optimizer_integration.rs @@ -215,15 +215,15 @@ impl ContextProvider for MyContextProvider { &self.options } - fn udfs_names(&self) -> Vec { + fn udf_names(&self) -> Vec { Vec::new() } - fn udafs_names(&self) -> Vec { + fn udaf_names(&self) -> Vec { Vec::new() } - fn udwfs_names(&self) -> Vec { + fn udwf_names(&self) -> Vec { Vec::new() } } diff --git a/datafusion/optimizer/tests/optimizer_integration.rs b/datafusion/optimizer/tests/optimizer_integration.rs index 2936d825ee39..b2fbc26ebaf1 100644 --- a/datafusion/optimizer/tests/optimizer_integration.rs +++ b/datafusion/optimizer/tests/optimizer_integration.rs @@ -396,15 +396,15 @@ impl ContextProvider for MyContextProvider { &self.options } - fn udfs_names(&self) -> Vec { + fn udf_names(&self) -> Vec { Vec::new() } - fn udafs_names(&self) -> Vec { + fn udaf_names(&self) -> Vec { Vec::new() } - fn udwfs_names(&self) -> Vec { + fn udwf_names(&self) -> Vec { Vec::new() } } diff --git a/datafusion/sql/examples/sql.rs b/datafusion/sql/examples/sql.rs index 5bab2f19cfc0..5989d5be4aa6 100644 --- a/datafusion/sql/examples/sql.rs +++ b/datafusion/sql/examples/sql.rs @@ -132,15 +132,15 @@ impl ContextProvider for MyContextProvider { &self.options } - fn udfs_names(&self) -> Vec { + fn udf_names(&self) -> Vec { Vec::new() } - fn udafs_names(&self) -> Vec { + fn udaf_names(&self) -> Vec { Vec::new() } - fn udwfs_names(&self) -> Vec { + fn udwf_names(&self) -> Vec { Vec::new() } } diff --git a/datafusion/sql/src/expr/function.rs b/datafusion/sql/src/expr/function.rs index dc0ddd4714dd..7abe5ecdae9f 100644 --- a/datafusion/sql/src/expr/function.rs +++ b/datafusion/sql/src/expr/function.rs @@ -46,18 +46,18 @@ pub fn suggest_valid_function( let mut funcs = Vec::new(); funcs.extend(AggregateFunction::iter().map(|func| func.to_string())); - funcs.extend(ctx.udafs_names()); + funcs.extend(ctx.udaf_names()); funcs.extend(BuiltInWindowFunction::iter().map(|func| func.to_string())); - funcs.extend(ctx.udwfs_names()); + funcs.extend(ctx.udwf_names()); funcs } else { // All scalar functions and aggregate functions let mut funcs = Vec::new(); - funcs.extend(ctx.udfs_names()); + funcs.extend(ctx.udf_names()); funcs.extend(AggregateFunction::iter().map(|func| func.to_string())); - funcs.extend(ctx.udafs_names()); + funcs.extend(ctx.udaf_names()); funcs }; diff --git a/datafusion/sql/src/expr/mod.rs b/datafusion/sql/src/expr/mod.rs index 6445c3f7a885..d34aa4cec520 100644 --- a/datafusion/sql/src/expr/mod.rs +++ b/datafusion/sql/src/expr/mod.rs @@ -1133,15 +1133,15 @@ mod tests { None } - fn udfs_names(&self) -> Vec { + fn udf_names(&self) -> Vec { Vec::new() } - fn udafs_names(&self) -> Vec { + fn udaf_names(&self) -> Vec { Vec::new() } - fn udwfs_names(&self) -> Vec { + fn udwf_names(&self) -> Vec { Vec::new() } } diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs index 0066f75f0d30..ed9d34722537 100644 --- a/datafusion/sql/src/planner.rs +++ b/datafusion/sql/src/planner.rs @@ -46,10 +46,6 @@ use crate::utils::make_decimal_type; /// The ContextProvider trait allows the query planner to obtain meta-data about tables and /// functions referenced in SQL statements pub trait ContextProvider { - #[deprecated(since = "32.0.0", note = "please use `get_table_source` instead")] - fn get_table_provider(&self, name: TableReference) -> Result> { - self.get_table_source(name) - } /// Getter for a datasource fn get_table_source(&self, name: TableReference) -> Result>; /// Getter for a table function @@ -86,9 +82,14 @@ pub trait ContextProvider { /// Get configuration options fn options(&self) -> &ConfigOptions; - fn udfs_names(&self) -> Vec; - fn udafs_names(&self) -> Vec; - fn udwfs_names(&self) -> Vec; + /// Get all user defined scalar function names + fn udf_names(&self) -> Vec; + + /// Get all user defined aggregate function names + fn udaf_names(&self) -> Vec; + + /// Get all user defined window function names + fn udwf_names(&self) -> Vec; } /// SQL parser options diff --git a/datafusion/sql/tests/sql_integration.rs b/datafusion/sql/tests/sql_integration.rs index af4dac5f3f89..3247d7bb2026 100644 --- a/datafusion/sql/tests/sql_integration.rs +++ b/datafusion/sql/tests/sql_integration.rs @@ -2942,15 +2942,15 @@ impl ContextProvider for MockContextProvider { Ok(Arc::new(EmptyTable::new(schema))) } - fn udfs_names(&self) -> Vec { + fn udf_names(&self) -> Vec { self.udfs.keys().cloned().collect() } - fn udafs_names(&self) -> Vec { + fn udaf_names(&self) -> Vec { self.udafs.keys().cloned().collect() } - fn udwfs_names(&self) -> Vec { + fn udwf_names(&self) -> Vec { Vec::new() } }