-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Adds unit test for sampler aggregation #23243
Conversation
/** | ||
* Unwrap an aggregator. Used for testing. | ||
*/ | ||
public static Aggregator unwrap(Aggregator in) { |
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'm not super comfortable about exposing this but I can't think of a much better way to actually close the aggregations during testing without reworking aggregations to make parent aggs close their subaggregations.
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.
Maybe we could do searchContext.clearReleasables(Lifetime.PHASE)
like the main code does since all aggregators are supposed to register themselves on to the search context.
when(queryShardContext.fieldMapper(fieldType.name())).thenReturn(fieldType); | ||
when(queryShardContext.getForField(fieldType)).thenReturn(fieldData); | ||
when(queryShardContext.getForField(fieldType)).then(invocation -> fieldType.fielddataBuilder().build( |
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.
This blew up without fielddata enabled so I made it return when used instead of all the time.
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.
makes sense
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 left a suggestion for the closing issue.
/** | ||
* Unwrap an aggregator. Used for testing. | ||
*/ | ||
public static Aggregator unwrap(Aggregator in) { |
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.
Maybe we could do searchContext.clearReleasables(Lifetime.PHASE)
like the main code does since all aggregators are supposed to register themselves on to the search context.
when(queryShardContext.fieldMapper(fieldType.name())).thenReturn(fieldType); | ||
when(queryShardContext.getForField(fieldType)).thenReturn(fieldData); | ||
when(queryShardContext.getForField(fieldType)).then(invocation -> fieldType.fielddataBuilder().build( |
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.
makes sense
Sampler sampler = searchAndReduce(searcher, new TermQuery(new Term("text", "good")), aggBuilder, textFieldType, | ||
numericFieldType); | ||
Min min = sampler.getAggregations().get("min"); | ||
assertEquals(5.0, min.getValue(), Double.MIN_NORMAL); |
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.
s/Double.MIN_NORMAL/0/ ? the computation of the min value should not be subject to accuracy issues.
@jpountz, I pushed the changes you asked for. Kind of. Have a look? |
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.
You are a mockito artist! LGTM.
Thanks! |
Grumble grumble, it looks like this merged instead of squashed, rebased, and merged. I must have lost my cookie.... Sorry! |
Backported to 5.x with d73d89c |
Relates to #22278