Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,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
Expand Down Expand Up @@ -1566,6 +1571,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
Expand Down Expand Up @@ -1605,6 +1624,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();
Expand Down
Loading