-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: UDF, UDAF, UDWF with_alias(..) should wrap the inner function fully #12098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
51bc3ba
33b89ce
175b8d2
3fb25af
1921f28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -442,7 +442,7 @@ pub trait AggregateUDFImpl: Debug + Send + Sync { | |
| /// not implement the method, returns an error. Order insensitive and hard | ||
| /// requirement aggregators return `Ok(None)`. | ||
| fn with_beneficial_ordering( | ||
| self: Arc<Self>, | ||
| &self, | ||
| _beneficial_ordering: bool, | ||
| ) -> Result<Option<Arc<dyn AggregateUDFImpl>>> { | ||
| if self.order_sensitivity().is_beneficial() { | ||
|
|
@@ -608,6 +608,60 @@ impl AggregateUDFImpl for AliasedAggregateUDFImpl { | |
| &self.aliases | ||
| } | ||
|
|
||
| fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 nice - to avoid similar bugs in the future maybe we should also add a comment to It would be cool if we could tell Rust not to create a default implementation for a particular
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added notes in 175b8d2. And yep - it would be nice to have a way of enforcing this, but I also couldn't figure out any way to do that :/ |
||
| self.inner.state_fields(args) | ||
| } | ||
|
|
||
| fn groups_accumulator_supported(&self, args: AccumulatorArgs) -> bool { | ||
| self.inner.groups_accumulator_supported(args) | ||
| } | ||
|
|
||
| fn create_groups_accumulator( | ||
| &self, | ||
| args: AccumulatorArgs, | ||
| ) -> Result<Box<dyn GroupsAccumulator>> { | ||
| self.inner.create_groups_accumulator(args) | ||
| } | ||
|
|
||
| fn create_sliding_accumulator( | ||
| &self, | ||
| args: AccumulatorArgs, | ||
| ) -> Result<Box<dyn Accumulator>> { | ||
| self.inner.accumulator(args) | ||
| } | ||
|
|
||
| fn with_beneficial_ordering( | ||
| &self, | ||
| beneficial_ordering: bool, | ||
| ) -> Result<Option<Arc<dyn AggregateUDFImpl>>> { | ||
| self.inner | ||
| .with_beneficial_ordering(beneficial_ordering) | ||
| .map(|udf| { | ||
| udf.map(|udf| { | ||
| Arc::new(AliasedAggregateUDFImpl { | ||
| inner: udf, | ||
| aliases: self.aliases.clone(), | ||
| }) as Arc<dyn AggregateUDFImpl> | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| fn order_sensitivity(&self) -> AggregateOrderSensitivity { | ||
| self.inner.order_sensitivity() | ||
| } | ||
|
|
||
| fn simplify(&self) -> Option<AggregateFunctionSimplification> { | ||
| self.inner.simplify() | ||
| } | ||
|
|
||
| fn reverse_expr(&self) -> ReversedUDAF { | ||
| self.inner.reverse_expr() | ||
| } | ||
|
|
||
| fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> { | ||
| self.inner.coerce_types(arg_types) | ||
| } | ||
|
|
||
| fn equals(&self, other: &dyn AggregateUDFImpl) -> bool { | ||
| if let Some(other) = other.as_any().downcast_ref::<AliasedAggregateUDFImpl>() { | ||
| self.inner.equals(other.inner.as_ref()) && self.aliases == other.aliases | ||
|
|
@@ -622,6 +676,10 @@ impl AggregateUDFImpl for AliasedAggregateUDFImpl { | |
| self.aliases.hash(hasher); | ||
| hasher.finish() | ||
| } | ||
|
|
||
| fn is_descending(&self) -> Option<bool> { | ||
| self.inner.is_descending() | ||
| } | ||
| } | ||
|
|
||
| /// Implementation of [`AggregateUDFImpl`] that wraps the function style pointers | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Arc<Self>was hard to call from the aliased version. Is there a reason why it was Arc'd?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea is that passing through the
&Arcallows the result to be created without a deep copy., though maybe it is being overly optimized 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, dunno if there is a difference between passing an Arc and &self perf wise - neither should require copy. But I got it work with the Arc<> (by adding a .clone() there, but that should only clone the pointer and not the self so I think that's fine as well), so then I don't need to change this and that's probably safer 😅
fixed in 33b89ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the
Arcin the API is wonky -- it definitely might be better to remove it. Thank you for considering doing so in a follow on PR