You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/05/19 22:38:07 UTC

(datafusion) 01/01: minor: add higher-order function methods to SessionContext (#21950)

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

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-21950-abfa5f2d0e0690dc8819e31f9472c23db5db3ccb
in repository https://gitbox.apache.org/repos/asf/datafusion.git

commit 5876a1af38cfb8b9755d366b5062caf245839015
Author: gstvg <28...@users.noreply.github.com>
AuthorDate: Tue May 19 17:12:07 2026 -0300

    minor: add higher-order function methods to SessionContext (#21950)
    
    ## Which issue does this PR close?
    
    Follow-up of #21679 that forgot to add these methods to `SessionContext`
    
    ## Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    -->
    
    ## What changes are included in this PR?
    
    <!--
    There is no need to duplicate the description in the issue here but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    ## Are these changes tested?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    -->
    
    ## Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    -->
    
    <!--
    If there are any breaking changes to public APIs, please add the `api
    change` label.
    -->
---
 datafusion/core/src/execution/context/mod.rs       | 32 ++++++++++++++++++++++
 docs/source/library-user-guide/upgrading/54.0.0.md | 23 ++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs
index 5770c20262..67dbe6b740 100644
--- a/datafusion/core/src/execution/context/mod.rs
+++ b/datafusion/core/src/execution/context/mod.rs
@@ -1496,6 +1496,9 @@ impl SessionContext {
             RegisterFunction::Window(f) => {
                 self.state.write().register_udwf(f)?;
             }
+            RegisterFunction::HigherOrder(f) => {
+                self.state.write().register_higher_order_function(f)?;
+            }
             RegisterFunction::Table(name, f) => self.register_udtf(&name, f),
         };
 
@@ -1510,6 +1513,11 @@ impl SessionContext {
         dropped |= self.state.write().deregister_udaf(&stmt.name)?.is_some();
         dropped |= self.state.write().deregister_udwf(&stmt.name)?.is_some();
         dropped |= self.state.write().deregister_udtf(&stmt.name)?.is_some();
+        dropped |= self
+            .state
+            .write()
+            .deregister_higher_order_function(&stmt.name)?
+            .is_some();
 
         // DROP FUNCTION IF EXISTS drops the specified function only if that
         // function exists and in this way, it avoids error. While the DROP FUNCTION
@@ -1609,6 +1617,20 @@ impl SessionContext {
         state.register_udf(Arc::new(f)).ok();
     }
 
+    /// Registers a higher-order function within this context.
+    ///
+    /// Note in SQL queries, function names are looked up using
+    /// lowercase unless the query uses quotes. For example,
+    ///
+    /// - `SELECT MY_HIGHER_ORDER_FUNC(x)...` will look for a function named `"my_higher_order_func"`
+    /// - `SELECT "my_HIGHER_ORDER_FUNC"(x)` will look for a function named `"my_HIGHER_ORDER_FUNC"`
+    ///
+    /// Any functions registered with the function name or its aliases will be overwritten with this new function
+    pub fn register_higher_order_function(&self, f: Arc<dyn HigherOrderUDF>) {
+        let mut state = self.state.write();
+        state.register_higher_order_function(f).ok();
+    }
+
     /// Registers an aggregate UDF within this context.
     ///
     /// Note in SQL queries, aggregate names are looked up using
@@ -1648,6 +1670,14 @@ impl SessionContext {
         self.state.write().deregister_udf(name).ok();
     }
 
+    /// Deregisters a higher-order function within this context.
+    pub fn deregister_higher_order_function(&self, name: &str) {
+        self.state
+            .write()
+            .deregister_higher_order_function(name)
+            .ok();
+    }
+
     /// Deregisters a UDAF within this context.
     pub fn deregister_udaf(&self, name: &str) {
         self.state.write().deregister_udaf(name).ok();
@@ -2190,6 +2220,8 @@ pub enum RegisterFunction {
     Aggregate(Arc<AggregateUDF>),
     /// Window user defined function
     Window(Arc<WindowUDF>),
+    /// Higher-order user defined function
+    HigherOrder(Arc<dyn HigherOrderUDF>),
     /// Table user defined function
     Table(String, Arc<dyn TableFunctionImpl>),
 }
diff --git a/docs/source/library-user-guide/upgrading/54.0.0.md b/docs/source/library-user-guide/upgrading/54.0.0.md
index 833164f58b..9643d1e936 100644
--- a/docs/source/library-user-guide/upgrading/54.0.0.md
+++ b/docs/source/library-user-guide/upgrading/54.0.0.md
@@ -787,3 +787,26 @@ a combined `OR` (e.g., index-backed sources).
 ```sql
 SET datafusion.optimizer.enable_unions_to_filter = true;
 ```
+
+### The `RegisterFunction` enum has a new `HigherOrder` variant
+
+`RegisterFunction` now has a `HigherOrder(Arc<dyn HigherOrderUDF>)` variant
+so user-defined higher-order functions can be registered
+
+**Who is affected:**
+
+- Users who match on a `RegisterFunction` without a default branch `_ => {}`
+
+**Migration guide:**
+
+Add the new branch to the match with the logic applicable to the context.
+
+```diff
+match register_function {
+    RegisterFunction::Scalar(scalar) => {},
+    RegisterFunction::Aggregate(aggregate) => {},
+    RegisterFunction::Window(window) => {},
++   RegisterFunction::HigherOrder(higher_order) => {},
+    RegisterFunction::Table(name, table) => {},
+}
+```


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org