diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs index de1d40dda349..fb5e2e02234c 100644 --- a/datafusion/core/src/execution/context/mod.rs +++ b/datafusion/core/src/execution/context/mod.rs @@ -1727,6 +1727,14 @@ impl FunctionRegistry for SessionContext { ) -> Result<()> { self.state.write().register_expr_planner(expr_planner) } + + fn udafs(&self) -> HashSet { + self.state.read().udafs() + } + + fn udwfs(&self) -> HashSet { + self.state.read().udwfs() + } } /// Create a new task context instance from SessionContext diff --git a/datafusion/core/src/execution/session_state.rs b/datafusion/core/src/execution/session_state.rs index a7b3bdeeace8..38212167f931 100644 --- a/datafusion/core/src/execution/session_state.rs +++ b/datafusion/core/src/execution/session_state.rs @@ -1875,6 +1875,14 @@ impl FunctionRegistry for SessionState { self.expr_planners.push(expr_planner); Ok(()) } + + fn udafs(&self) -> HashSet { + self.aggregate_functions.keys().cloned().collect() + } + + fn udwfs(&self) -> HashSet { + self.window_functions.keys().cloned().collect() + } } impl OptimizerConfig for SessionState { diff --git a/datafusion/execution/src/task.rs b/datafusion/execution/src/task.rs index b11596c4a30f..19f97f9e79ec 100644 --- a/datafusion/execution/src/task.rs +++ b/datafusion/execution/src/task.rs @@ -201,6 +201,14 @@ impl FunctionRegistry for TaskContext { fn expr_planners(&self) -> Vec> { vec![] } + + fn udafs(&self) -> HashSet { + self.aggregate_functions.keys().cloned().collect() + } + + fn udwfs(&self) -> HashSet { + self.window_functions.keys().cloned().collect() + } } #[cfg(test)] diff --git a/datafusion/expr/src/registry.rs b/datafusion/expr/src/registry.rs index 4eb49710bcf8..8ea9e34dac12 100644 --- a/datafusion/expr/src/registry.rs +++ b/datafusion/expr/src/registry.rs @@ -27,9 +27,25 @@ use std::sync::Arc; /// A registry knows how to build logical expressions out of user-defined function' names pub trait FunctionRegistry { - /// Set of all available udfs. + /// Returns names of all available scalar user defined functions. fn udfs(&self) -> HashSet; + /// Returns names of all available aggregate user defined functions. + fn udafs(&self) -> HashSet { + // This default implementation is provided temporarily + // to maintain backward compatibility for the 50.1 release. + // It will be reverted to a required method in future versions. + HashSet::default() + } + + /// Returns names of all available window user defined functions. + fn udwfs(&self) -> HashSet { + // This default implementation is provided temporarily + // to maintain backward compatibility for the 50.1 release. + // It will be reverted to a required method in future versions. + HashSet::default() + } + /// Returns a reference to the user defined scalar function (udf) named /// `name`. fn udf(&self, name: &str) -> Result>; @@ -200,4 +216,12 @@ impl FunctionRegistry for MemoryFunctionRegistry { fn expr_planners(&self) -> Vec> { vec![] } + + fn udafs(&self) -> HashSet { + self.udafs.keys().cloned().collect() + } + + fn udwfs(&self) -> HashSet { + self.udwfs.keys().cloned().collect() + } } diff --git a/datafusion/proto/src/bytes/mod.rs b/datafusion/proto/src/bytes/mod.rs index da01d89c0c3d..16d65c419ae6 100644 --- a/datafusion/proto/src/bytes/mod.rs +++ b/datafusion/proto/src/bytes/mod.rs @@ -170,6 +170,14 @@ impl Serializeable for Expr { fn expr_planners(&self) -> Vec> { vec![] } + + fn udafs(&self) -> std::collections::HashSet { + std::collections::HashSet::default() + } + + fn udwfs(&self) -> std::collections::HashSet { + std::collections::HashSet::default() + } } Expr::from_bytes_with_registry(&bytes, &PlaceHolderRegistry)?; diff --git a/datafusion/proto/src/bytes/registry.rs b/datafusion/proto/src/bytes/registry.rs index eae2425f8ac1..5d46d41f793e 100644 --- a/datafusion/proto/src/bytes/registry.rs +++ b/datafusion/proto/src/bytes/registry.rs @@ -59,4 +59,12 @@ impl FunctionRegistry for NoRegistry { fn expr_planners(&self) -> Vec> { vec![] } + + fn udafs(&self) -> HashSet { + HashSet::new() + } + + fn udwfs(&self) -> HashSet { + HashSet::new() + } } diff --git a/datafusion/spark/src/lib.rs b/datafusion/spark/src/lib.rs index 531883a6c4b2..bec7d90062eb 100644 --- a/datafusion/spark/src/lib.rs +++ b/datafusion/spark/src/lib.rs @@ -53,6 +53,8 @@ //! # impl FunctionRegistry for SessionContext { //! # fn register_udf(&mut self, _udf: Arc) -> Result>> { Ok (None) } //! # fn udfs(&self) -> HashSet { unimplemented!() } +//! # fn udafs(&self) -> HashSet { unimplemented!() } +//! # fn udwfs(&self) -> HashSet { unimplemented!() } //! # fn udf(&self, _name: &str) -> Result> { unimplemented!() } //! # fn udaf(&self, name: &str) -> Result> {unimplemented!() } //! # fn udwf(&self, name: &str) -> Result> { unimplemented!() }