-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Fix terms aggregation doc_count_error_upper_bound for already reduced results (batched query phase) #134645
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
base: main
Are you sure you want to change the base?
Fix terms aggregation doc_count_error_upper_bound for already reduced results (batched query phase) #134645
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ public interface Builder { | |
@Nullable | ||
private final AggregationBuilder builder; | ||
private final AggregatorFactories.Builder subBuilders; | ||
private boolean finalReduceHasBatchedResult; | ||
|
||
private AggregationReduceContext( | ||
BigArrays bigArrays, | ||
|
@@ -136,6 +137,14 @@ public final AggregationReduceContext forAgg(String name) { | |
|
||
protected abstract AggregationReduceContext forSubAgg(AggregationBuilder sub); | ||
|
||
public boolean doesFinalReduceHaveBatchedResult() { | ||
return finalReduceHasBatchedResult; | ||
} | ||
|
||
public void setFinalReduceHasBatchedResult(boolean finalReduceHasBatchedResult) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be final and set in the ForFinal ctr? |
||
this.finalReduceHasBatchedResult = finalReduceHasBatchedResult; | ||
} | ||
|
||
/** | ||
* A {@linkplain AggregationReduceContext} to perform a partial reduction. | ||
*/ | ||
|
@@ -234,7 +243,9 @@ public PipelineTree pipelineTreeRoot() { | |
|
||
@Override | ||
protected AggregationReduceContext forSubAgg(AggregationBuilder sub) { | ||
return new ForFinal(bigArrays(), scriptService(), isCanceled(), sub, multiBucketConsumer, pipelineTreeRoot); | ||
ForFinal subContext = new ForFinal(bigArrays(), scriptService(), isCanceled(), sub, multiBucketConsumer, pipelineTreeRoot); | ||
subContext.setFinalReduceHasBatchedResult(doesFinalReduceHaveBatchedResult()); | ||
return subContext; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,7 +332,10 @@ public InternalAggregation get() { | |
} | ||
long docCountError = -1; | ||
if (sumDocCountError != -1) { | ||
docCountError = size == 1 ? 0 : sumDocCountError; | ||
// If we are reducing only one aggregation (size == 1), the doc count error should be 0. | ||
// However, the presence of a batched query result implies this is a final reduction and a partial reduction with size > 1 | ||
// has already occurred on a data node. The doc count error should not be 0 in this case. | ||
docCountError = size == 1 && reduceContext.doesFinalReduceHaveBatchedResult() == false ? 0 : sumDocCountError; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that also handle the case where the partial reduction happens on the coord node (when reaching reduce batch size)? |
||
} | ||
return create(name, result, reduceContext.isFinalReduce() ? getOrder() : thisReduceOrder, docCountError, otherDocCount); | ||
} | ||
|
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.
nit: that feels weird since it depends on
isFinalReduce
? Maybe rename it intohasBatchedResult
so that callers have to checkisFinalReduce
andhasBatchedResult
?