You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "findepi (via GitHub)" <gi...@apache.org> on 2025/02/07 13:04:17 UTC
[PR] Allow constructing ScalarUDF from shared implementation [datafusion]
findepi opened a new pull request, #14541:
URL: https://github.com/apache/datafusion/pull/14541
When composing or decorating functions, it's useful to operate on Impl trait objects (dyn ScalarUDFImpl) instead of the Expr-level adapter (ScalarUDF). However, before the change, it was impossible to construct `ScalarUDF` from `Arc<dyn ScalarUDFImpl>`, even though the use of `Arc` is already part of the type API. This commit allows constructing the scalar from a shared impl object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14541:
URL: https://github.com/apache/datafusion/pull/14541#discussion_r1946990866
##########
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
Review Comment:
> Into/From is very important for readability in some cases, but it can also [be abused](https://github.com/apache/datafusion/blob/d5ff3e7c247430865590c592587ad60fdff4bcc0/datafusion/common/src/scalar/mod.rs#L3453). Sometimes just single API method is enough
I agree -- that one should be an API method (not just a From impl) to make it easier to find/use. Filed
- https://github.com/apache/datafusion/issues/14548
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14541:
URL: https://github.com/apache/datafusion/pull/14541#discussion_r1946983077
##########
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
Review Comment:
To be clear, I am suggesting it in addition to this explicit function. I don't have a strong opinion
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14541:
URL: https://github.com/apache/datafusion/pull/14541#discussion_r1946707537
##########
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
Review Comment:
BTW it might also be nice to add a `From` impl for this similar to
https://github.com/apache/datafusion/blob/4f6062e81b7201b58da2b20c63333a5e3ae3c8df/datafusion/expr/src/udaf.rs#L288-L295
That would allow creation using
```rust
let fun: fun: Arc<dyn AggregateUDFImpl> = ...;
// create using `from`:
let new_func = AggregateUDFImpl::from(fun);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi merged PR #14541:
URL: https://github.com/apache/datafusion/pull/14541
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #14541:
URL: https://github.com/apache/datafusion/pull/14541#discussion_r1947197259
##########
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
Review Comment:
thanks for filing that issue! ❤️
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14541:
URL: https://github.com/apache/datafusion/pull/14541#discussion_r1946707537
##########
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
Review Comment:
I suggest also adding `From` impls for these functions similar to
https://github.com/apache/datafusion/blob/4f6062e81b7201b58da2b20c63333a5e3ae3c8df/datafusion/expr/src/udaf.rs#L288-L295
That would allow creation using
```rust
let fun: fun: Arc<dyn AggregateUDFImpl> = ...;
// create using `from`:
let new_func = AggregateUDFImpl::from(fun);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #14541:
URL: https://github.com/apache/datafusion/pull/14541#discussion_r1947197039
##########
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
Review Comment:
> To be clear, I am suggesting it in addition to this explicit function. I don't have a strong opinion
i don't very strong either here, just didn't see need for that
let's revisit if needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow constructing ScalarUDF from shared implementation [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #14541:
URL: https://github.com/apache/datafusion/pull/14541#discussion_r1946891887
##########
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
Review Comment:
i am not against `AggregateUDFImpl::from` explicit syntax, but i am not a big fan of `.into()` implicit syntax that this unlocks
Into/From is very important for readability in some cases, but it can also [be abused](https://github.com/apache/datafusion/blob/d5ff3e7c247430865590c592587ad60fdff4bcc0/datafusion/common/src/scalar/mod.rs#L3453). Sometimes just single API method is enough
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org