Skip to content

Apache DataFusion SQL Query Engine

Allow constructing ScalarUDF from shared implementation (#14541)

Piotr Findeisen22fb5f7aaf7b
diff --git a/datafusion/expr/src/udaf.rs b/datafusion/expr/src/udaf.rs
index 84a513b21b..7ffc6623ea 100644
--- a/datafusion/expr/src/udaf.rs
+++ b/datafusion/expr/src/udaf.rs
@@ -119,9 +119,12 @@ impl AggregateUDF {
where
F: AggregateUDFImpl + 'static,
{
- Self {
- inner: Arc::new(fun),
- }
+ Self::new_from_shared_impl(Arc::new(fun))
+ }
+
+ /// Create a new `AggregateUDF` from a `[AggregateUDFImpl]` trait object
+ pub fn new_from_shared_impl(fun: Arc<dyn AggregateUDFImpl>) -> AggregateUDF {
+ Self { inner: fun }
}
/// Return the underlying [`AggregateUDFImpl`] trait object for this function
diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs
index aa6a5cddad..b41d975203 100644
--- a/datafusion/expr/src/udf.rs
+++ b/datafusion/expr/src/udf.rs
@@ -91,9 +91,12 @@ impl ScalarUDF {
where
F: ScalarUDFImpl + 'static,
{
- Self {
- inner: Arc::new(fun),
- }
+ Self::new_from_shared_impl(Arc::new(fun))
+ }
+
+ /// Create a new `ScalarUDF` from a `[ScalarUDFImpl]` trait object
+ pub fn new_from_shared_impl(fun: Arc<dyn ScalarUDFImpl>) -> ScalarUDF {
+ Self { inner: fun }
}
/// Return the underlying [`ScalarUDFImpl`] trait object for this function
diff --git a/datafusion/expr/src/udwf.rs b/datafusion/expr/src/udwf.rs
index 39e1e8f261..96929ffeb0 100644
--- a/datafusion/expr/src/udwf.rs
+++ b/datafusion/expr/src/udwf.rs
@@ -100,9 +100,12 @@ impl WindowUDF {
where
F: WindowUDFImpl + 'static,
{
- Self {
- inner: Arc::new(fun),
- }
+ Self::new_from_shared_impl(Arc::new(fun))
+ }
+
+ /// Create a new `WindowUDF` from a `[WindowUDFImpl]` trait object
+ pub fn new_from_shared_impl(fun: Arc<dyn WindowUDFImpl>) -> WindowUDF {
+ Self { inner: fun }
}
/// Return the underlying [`WindowUDFImpl`] trait object for this function