This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch branch-50
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/branch-50 by this push:
     new 14da942f81 feat: expose `udafs` and `udwfs` methods on 
`FunctionRegistry` (#17650) (#17725)
14da942f81 is described below

commit 14da942f81153d7f10644fba16add6b298e5b536
Author: Marko Milenković <[email protected]>
AuthorDate: Mon Sep 22 18:19:44 2025 +0100

    feat: expose `udafs` and `udwfs` methods on `FunctionRegistry` (#17650) 
(#17725)
    
    * expose udafs and udwfs method on `FunctionRegistry`
    
    * fix doc test
    
    * add default implementations not to trigger
    backward incompatible change for others
---
 datafusion/core/src/execution/context/mod.rs   |  8 ++++++++
 datafusion/core/src/execution/session_state.rs |  8 ++++++++
 datafusion/execution/src/task.rs               |  8 ++++++++
 datafusion/expr/src/registry.rs                | 26 +++++++++++++++++++++++++-
 datafusion/proto/src/bytes/mod.rs              |  8 ++++++++
 datafusion/proto/src/bytes/registry.rs         |  8 ++++++++
 datafusion/spark/src/lib.rs                    |  2 ++
 7 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/datafusion/core/src/execution/context/mod.rs 
b/datafusion/core/src/execution/context/mod.rs
index de1d40dda3..fb5e2e0223 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<String> {
+        self.state.read().udafs()
+    }
+
+    fn udwfs(&self) -> HashSet<String> {
+        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 a7b3bdeeac..38212167f9 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<String> {
+        self.aggregate_functions.keys().cloned().collect()
+    }
+
+    fn udwfs(&self) -> HashSet<String> {
+        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 b11596c4a3..19f97f9e79 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<Arc<dyn ExprPlanner>> {
         vec![]
     }
+
+    fn udafs(&self) -> HashSet<String> {
+        self.aggregate_functions.keys().cloned().collect()
+    }
+
+    fn udwfs(&self) -> HashSet<String> {
+        self.window_functions.keys().cloned().collect()
+    }
 }
 
 #[cfg(test)]
diff --git a/datafusion/expr/src/registry.rs b/datafusion/expr/src/registry.rs
index 4eb49710bc..8ea9e34dac 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<String>;
 
+    /// Returns names of all available aggregate user defined functions.
+    fn udafs(&self) -> HashSet<String> {
+        // 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<String> {
+        // 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<Arc<ScalarUDF>>;
@@ -200,4 +216,12 @@ impl FunctionRegistry for MemoryFunctionRegistry {
     fn expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>> {
         vec![]
     }
+
+    fn udafs(&self) -> HashSet<String> {
+        self.udafs.keys().cloned().collect()
+    }
+
+    fn udwfs(&self) -> HashSet<String> {
+        self.udwfs.keys().cloned().collect()
+    }
 }
diff --git a/datafusion/proto/src/bytes/mod.rs 
b/datafusion/proto/src/bytes/mod.rs
index da01d89c0c..16d65c419a 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<Arc<dyn ExprPlanner>> {
                 vec![]
             }
+
+            fn udafs(&self) -> std::collections::HashSet<String> {
+                std::collections::HashSet::default()
+            }
+
+            fn udwfs(&self) -> std::collections::HashSet<String> {
+                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 eae2425f8a..5d46d41f79 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<Arc<dyn ExprPlanner>> {
         vec![]
     }
+
+    fn udafs(&self) -> HashSet<String> {
+        HashSet::new()
+    }
+
+    fn udwfs(&self) -> HashSet<String> {
+        HashSet::new()
+    }
 }
diff --git a/datafusion/spark/src/lib.rs b/datafusion/spark/src/lib.rs
index 531883a6c4..bec7d90062 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<ScalarUDF>) -> 
Result<Option<Arc<ScalarUDF>>> { Ok (None) }
 //! #    fn udfs(&self) -> HashSet<String> { unimplemented!() }
+//! #    fn udafs(&self) -> HashSet<String> { unimplemented!() }
+//! #    fn udwfs(&self) -> HashSet<String> { unimplemented!() }
 //! #    fn udf(&self, _name: &str) -> Result<Arc<ScalarUDF>> { 
unimplemented!() }
 //! #    fn udaf(&self, name: &str) -> Result<Arc<AggregateUDF>> 
{unimplemented!() }
 //! #    fn udwf(&self, name: &str) -> Result<Arc<WindowUDF>> { 
unimplemented!() }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to