datafusion
datafusion copied to clipboard
Implement `Eq`, `PartialEq`, `Hash` for `dyn PhysicalExpr`
Which issue does this PR close?
Part of https://github.com/apache/datafusion/issues/12599.
Rationale for this change
Common subexpression elimination will require Arc<dyn PhysicalExpr> tree nodes to implement Eq, PartialEq, Hash.
What changes are included in this PR?
This PR:
- Refactors
PhysicalExprtrait and movesdyn_hash()to a newDynHashtrait. - Adds blanket implementation of
DynHashfor types that implementHash. This enables us to drop most of the previousdyn_hash()boilerplate implementations. - Introduces
DynEqtrait withdyn_eq(). - Adds blanket implementation of
DynEqfor types that implementEq.
Please note that:
- This PR contains an API breaking change that
dyn_hash()is moved fromPhysicalExprto separateDynHashtrait. - This PR contains a small hack that some
PhysicalExprimplementations (likeBinaryExpr) got a new generic parameter calledDynPhysicalExpr(e.g.struct BinaryExpr<DynPhysicalExpr: ?Sized = dyn PhysicalExpr>). This was needed due to a rust bug: https://github.com/rust-lang/rust/issues/78808. This hack: https://github.com/rust-lang/rust/issues/78808#issuecomment-1664416547 allows us to derivePartialEqinstead of implementing it separately for the affected types.
Are these changes tested?
Yes, with existing tests.
Are there any user-facing changes?
No.
cc @alamb
On my list for review tomorrow
What I would like to propose for this PR is wait until we have made the next release: #12470 and then we can merge it after that
I am thinking of how we can spread out the API upgrade pain
The 43.0.0 release candidate has been made and we have started voting on it. I merged this branch up from main locally to ensure everything still compiles. It looks good so this is ready to go 🏁
THanks again @peter-toth and @berkaysynnada
Thanks for review @alamb and @berkaysynnada.