You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change Expr PartialOrd to not rely on comparing hash values #8932
I expect that PartialOrd of Expr will not change -- we probably have to implement a real PartialOrd implementation that compares each field (or maybe derive)
Edit: as suspected it looks like PartialEq is being derived using a proc macro, and is therefore inconsistent with this implementation of PartialOrd - https://github.com/apache/arrow-datafusion/blob/main/datafusion/expr/src/expr.rs#L87. In particular PartialOrd could claim things to be equal due to a hash collision, when PartialEq would indicate they are not
So my conclusion is that this is a latent bug waiting to happen (that will be very hard to track down if/when it does strike)
Reacted by Raphael Taylor-Davies, Liang-Chi Hsieh and Oleks V
changed the title [-]Change Expr ordering so it does not rely on `PartialOrd`[/-][+]Change Expr `PartialOrd` to not rely on comparing hash values[/+]on Jan 21, 2024
Hi, I'm new to this project and was poking through the issues, can I try working this one out?
It looks like, to remove the hash we would need to first compare by enum variant (it looks like based on the test that the declaration order determines the Ord). I see two solutions for this, either implementing a "discriminant" function to determine the variant ordering, or by having a lot of match arms.
In the case of equivalent variant, we can then compare by fields, looks like it should work for the majority of them.
Hi, I'm new to this project and was poking through the issues, can I try working this one out?
It looks like, to remove the hash we would need to first compare by enum variant (it looks like based on the test that the declaration order determines the Ord). I see two solutions for this, either implementing a "discriminant" function to determine the variant ordering, or by having a lot of match arms.
In the case of equivalent variant, we can then compare by fields, looks like it should work for the majority of them.
Is that the right track?
I think so . I don't think the actual relative order of Exprs is important, only that it is consistent
It might be worth figuring out how to break this work into some smaller PRs (rather than one large one) -- perhaps by implementing partial ord for sub fields / structs that are used in Expr before trying to do so for the whole thing.
I was going through the remaining subtypes/structs, and saw an issue that I wasn't sure how to resolve. While most of the remaining can derive PartialOrd, it looks like DFSchema can't, and since it has a dependency on a Hashmap. A similar problem happens in CreateExternalTable, which uses two Hashmaps. Not sure how to approach this, any advice would be appreciated!
I would personally suggest trying to simply ignore the contents of the schema for partial ord -- I think in general the other fields in structs should be enough to compute equality and ordering
Activity
alamb commentedon Jan 21, 2024
@tustvold notes on #8908 (comment):
So my conclusion is that this is a latent bug waiting to happen (that will be very hard to track down if/when it does strike)
[-]Change Expr ordering so it does not rely on `PartialOrd`[/-][+]Change Expr `PartialOrd` to not rely on comparing hash values[/+]ngli-me commentedon Sep 8, 2024
Hi, I'm new to this project and was poking through the issues, can I try working this one out?
It looks like, to remove the hash we would need to first compare by enum variant (it looks like based on the test that the declaration order determines the Ord). I see two solutions for this, either implementing a "discriminant" function to determine the variant ordering, or by having a lot of match arms.
In the case of equivalent variant, we can then compare by fields, looks like it should work for the majority of them.
Is that the right track?
alamb commentedon Sep 9, 2024
I think so . I don't think the actual relative order of
Exprs is important, only that it is consistentIt might be worth figuring out how to break this work into some smaller PRs (rather than one large one) -- perhaps by implementing partial ord for sub fields / structs that are used in Expr before trying to do so for the whole thing.
ngli-me commentedon Sep 9, 2024
Good idea! I went back through to check all the DF sub fields/structs, will start the work + breaking it down.
PartialOrd Status
ngli-me commentedon Sep 14, 2024
I was going through the remaining subtypes/structs, and saw an issue that I wasn't sure how to resolve. While most of the remaining can derive PartialOrd, it looks like
DFSchemacan't, and since it has a dependency on a Hashmap. A similar problem happens inCreateExternalTable, which uses two Hashmaps. Not sure how to approach this, any advice would be appreciated!alamb commentedon Sep 14, 2024
I would personally suggest trying to simply ignore the contents of the schema for partial ord -- I think in general the other fields in structs should be enough to compute equality and ordering