-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Fix equals and hashCode in AggregationBuilder to be order independent #33942
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
Fix equals and hashCode in AggregationBuilder to be order independent #33942
Conversation
Pinging @elastic/es-search-aggs |
if (!Objects.equals(aggregationBuilders, other.aggregationBuilders)) | ||
|
||
// compare aggregations independent of their order | ||
if (!aggregationBuilders.containsAll(other.aggregationBuilders)) |
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 don't think this will satisfy the "equals" contract: !(A, B).constainsAll(A, B, C) but (A, B, C).constainsAll(A, B). I think and additional size check will solve this though.
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 wonder if it wouldn't be simpler to use HashSet
s instead of List
s in the Builder
. Even if the number of aggs should be low I don't like the fact that we call containsAll
on a list on every equals
call.
Good catch @cbuescher! - stupid mistake, happens if you think 'it's simple' ;-) @jimczi I was careful not to touch to the inner workings. I think the suggestion is good but - as I would replace the List with the Set - means changing an interface and therefore bigger changes all over the place. Nevertheless, I happily do it if everybody agrees. |
retest this please |
Note that for pipeline aggregations the order matters so we need to be careful turning Sets to Lists and make sure it's kept as a list after the order of execution of the pipeline aggregators is resolved |
fdfacfc
to
4867800
Compare
I created an alternative fix which uses Sets: #34005 As you can see this is a large re-factoring, but should work. @colings86 Regarding order of pipeline aggs: as far as I see it, this change does not touch the ordering but runs before aggregations are resolved. The order get's defined during Nevertheless we need to decide for one way or the other. |
Could you explain how the currenty "ordered" hashCode/equals affects the tests you are trying to get to pass? I'm a bit reluctant to complicate the existing hashCode/equals implementation if it is not motivated by requirements to the class itself. Maybe there are other ways to solve this that don't involve changing the interface or adding additional complexity to the two functions. Even it they currently seem only to be used by tests, these methods are an integral part of the classes behaviour and are likely to be used outside of tests at some point. |
In a nutshell: I have configuration objects which hold aggregations (similar to what rollup does). This configuration is serializeable. The test failures happen when testing end2end serializing/de-serializing. I can of course workaround it in my tests, but it feels odd to me. However, I am on the same page with you regarding the interface changes, this is a high price to pay for this fix. FWIW: AggregatorFactories.Builder implements |
Closing in favor of #34005 |
Fixes the equals and hash function to ignore the order of aggregations. Mainly for testing purposes.
Note:
The impact of this issue afaik only affects tests (-> non-issue), I am using aggregations and need this fix in order to get other tests green.