Skip to content

Commit 7dff1e1

Browse files
authored
minor: Make FunctionRegistry udafs and udwfs methods mandatory (#17847)
* make FunctionRegistry `udaf` and `udwf` methods mandatory * update upgrading guide
1 parent 1ac8186 commit 7dff1e1

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

datafusion/core/tests/user_defined/user_defined_aggregates.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use datafusion::{
5353
};
5454
use datafusion_common::{assert_contains, exec_datafusion_err};
5555
use datafusion_common::{cast::as_primitive_array, exec_err};
56+
5657
use datafusion_expr::expr::WindowFunction;
5758
use datafusion_expr::{
5859
col, create_udaf, function::AccumulatorArgs, AggregateUDFImpl, Expr,
@@ -297,10 +298,12 @@ async fn deregister_udaf() -> Result<()> {
297298
ctx.register_udaf(my_avg);
298299

299300
assert!(ctx.state().aggregate_functions().contains_key("my_avg"));
301+
assert!(datafusion_execution::FunctionRegistry::udafs(&ctx).contains("my_avg"));
300302

301303
ctx.deregister_udaf("my_avg");
302304

303305
assert!(!ctx.state().aggregate_functions().contains_key("my_avg"));
306+
assert!(!datafusion_execution::FunctionRegistry::udafs(&ctx).contains("my_avg"));
304307

305308
Ok(())
306309
}

datafusion/core/tests/user_defined/user_defined_scalar_functions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,12 @@ async fn deregister_udf() -> Result<()> {
775775
ctx.register_udf(cast2i64);
776776

777777
assert!(ctx.udfs().contains("cast_to_i64"));
778+
assert!(FunctionRegistry::udfs(&ctx).contains("cast_to_i64"));
778779

779780
ctx.deregister_udf("cast_to_i64");
780781

781782
assert!(!ctx.udfs().contains("cast_to_i64"));
783+
assert!(!FunctionRegistry::udfs(&ctx).contains("cast_to_i64"));
782784

783785
Ok(())
784786
}

datafusion/core/tests/user_defined/user_defined_window_functions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ async fn test_deregister_udwf() -> Result<()> {
128128
OddCounter::register(&mut ctx, Arc::clone(&test_state));
129129

130130
assert!(ctx.state().window_functions().contains_key("odd_counter"));
131+
assert!(datafusion_execution::FunctionRegistry::udwfs(&ctx).contains("odd_counter"));
131132

132133
ctx.deregister_udwf("odd_counter");
133134

134135
assert!(!ctx.state().window_functions().contains_key("odd_counter"));
136+
assert!(!datafusion_execution::FunctionRegistry::udwfs(&ctx).contains("odd_counter"));
135137

136138
Ok(())
137139
}

datafusion/expr/src/registry.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,10 @@ pub trait FunctionRegistry {
3131
fn udfs(&self) -> HashSet<String>;
3232

3333
/// Returns names of all available aggregate user defined functions.
34-
fn udafs(&self) -> HashSet<String> {
35-
// This default implementation is provided temporarily
36-
// to maintain backward compatibility for the 50.1 release.
37-
// It will be reverted to a required method in future versions.
38-
HashSet::default()
39-
}
34+
fn udafs(&self) -> HashSet<String>;
4035

4136
/// Returns names of all available window user defined functions.
42-
fn udwfs(&self) -> HashSet<String> {
43-
// This default implementation is provided temporarily
44-
// to maintain backward compatibility for the 50.1 release.
45-
// It will be reverted to a required method in future versions.
46-
HashSet::default()
47-
}
37+
fn udwfs(&self) -> HashSet<String>;
4838

4939
/// Returns a reference to the user defined scalar function (udf) named
5040
/// `name`.

docs/source/library-user-guide/upgrading.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ The Minimum Supported Rust Version (MSRV) has been updated to [`1.87.0`].
3131

3232
[`1.87.0`]: https://releases.rs/docs/1.87.0/
3333

34+
### `FunctionRegistry` exposes two additional methods
35+
36+
`FunctionRegistry` exposes two additional methods `udafs` and `udwfs` which expose set of registered user defined aggregation and window function names. To upgrade implement methods returning set of registered function names:
37+
38+
```diff
39+
impl FunctionRegistry for FunctionRegistryImpl {
40+
fn udfs(&self) -> HashSet<String> {
41+
self.scalar_functions.keys().cloned().collect()
42+
}
43+
+ fn udafs(&self) -> HashSet<String> {
44+
+ self.aggregate_functions.keys().cloned().collect()
45+
+ }
46+
+
47+
+ fn udwfs(&self) -> HashSet<String> {
48+
+ self.window_functions.keys().cloned().collect()
49+
+ }
50+
}
51+
```
52+
3453
### `datafusion-proto` use `TaskContext` rather than `SessionContext` in physical plan serde methods
3554

3655
There have been changes in the public API methods of `datafusion-proto` which handle physical plan serde.

0 commit comments

Comments
 (0)