Derive ScalarUDFImpl equality, hash from Eq, Hash traits#17164
Merged
findepi merged 2 commits intoapache:mainfrom Aug 13, 2025
Merged
Derive ScalarUDFImpl equality, hash from Eq, Hash traits#17164findepi merged 2 commits intoapache:mainfrom
ScalarUDFImpl equality, hash from Eq, Hash traits#17164findepi merged 2 commits intoapache:mainfrom
Conversation
6037ccb to
bff9ef1
Compare
Follows similar change for `WindowUDFImpl` and `AggregateUDFImpl`, i.e. the 8494a39 and b8bf7c5 commits. Previously, the `ScalarUDFImpl` trait contained `equals` and `hash_value` methods with contracts following the `Eq` and `Hash` traits. However, the existence of default implementations of these methods made it error-prone, with many functions (scalar, aggregate, window) missing to customize the equals even though they ought to. There is no fix to this that's not an API breaking change, so a breaking change is warranted. Removing the default implementations would be enough of a solution, but at the cost of a lot of boilerplate needed in implementations. Instead, this removes the methods from the trait, and reuses `DynEq`, `DynHash` traits used previously only for physical expressions. This allows for functions to provide their implementations using no more than `#[derive(PartialEq, Eq, Hash)]` in a typical case.
bff9ef1 to
e7a9934
Compare
findepi
commented
Aug 13, 2025
|
|
||
| - search for `\#\[derive\(Debug\)\](\n *(pub )?struct \w+ \{\n *signature\: Signature\,\n *\})`, | ||
| - replace with `#[derive(Debug, PartialEq, Eq, Hash)]$1`, | ||
| - review all the changes and make sure only function structs were changed. |
Member
Author
There was a problem hiding this comment.
Here is the only non-mechanical change in this PR.
Member
Author
There was a problem hiding this comment.
for reference, due to how DF functions are written, i used a different regex
\#\[derive\(Debug\)\](\n *(pub(\((super|crate)\))? )?struct \w+ \{\n( *name: String,\n)? *signature\: Signature\,\n( *aliases: Vec<String>,\n)? *\})
- still not perfect, eg some functions derive Clone (just because they can) and the pattern doesn't cater for this
- it's unlikely that downstream projects have fields such as
nameandaliasesin their functions, so I didn't cater for these in the upgrade guide.
timsaucer
approved these changes
Aug 13, 2025
alamb
approved these changes
Aug 13, 2025
Contributor
alamb
left a comment
There was a problem hiding this comment.
loogs good to me -- thanks @findepi and @timsaucer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows similar change for
WindowUDFImplandAggregateUDFImpl, i.e.the 8494a39 and b8bf7c5 commits.
Previously, the
ScalarUDFImpltrait containedequalsandhash_valuemethods with contracts following theEqandHashtraits. However, the existence of default implementations of these
methods made it error-prone, with many functions (scalar, aggregate,
window) missing to customize the equals even though they ought to.
There is no fix to this that's not an API breaking change, so a breaking
change is warranted.
Removing the default implementations would be enough of a solution, but
at the cost of a lot of boilerplate needed in implementations.
Instead, this removes the methods from the trait, and reuses
DynEq,DynHashtraits used previously only for physical expressions. Thisallows for functions to provide their implementations using no more than
#[derive(PartialEq, Eq, Hash)]in a typical case.WindowUDFImplequality, hash fromEq,Hashtraits #17081AggregateUDFImplequality, hash fromEq,Hashtraits #17130ScalarUDFImpl) #16868ScalarUDFImpl::{equals,hash_value}withUdfHash,UdfEqtraits #16871