Skip to content
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

[Backport 2.x] [bug fix] fix precompute ordering in max & min aggregator #17646

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@
if (valuesSource == null) {
return false;
}

if (pointConverter != null) {
Number segMax = findLeafMaxValue(ctx.reader(), pointField, pointConverter);
if (segMax != null) {
/*
* There is no parent aggregator (see {@link AggregatorBase#getPointReaderOrNull}
* so the ordinal for the bucket is always 0.
*/
assert maxes.size() == 1;
double max = maxes.get(0);
max = Math.max(max, segMax.doubleValue());
maxes.set(0, max);

Check warning on line 123 in server/src/main/java/org/opensearch/search/aggregations/metrics/MaxAggregator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/aggregations/metrics/MaxAggregator.java#L121-L123

Added lines #L121 - L123 were not covered by tests
// the maximum value has been extracted, we don't need to collect hits on this segment.
return true;

Check warning on line 125 in server/src/main/java/org/opensearch/search/aggregations/metrics/MaxAggregator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/aggregations/metrics/MaxAggregator.java#L125

Added line #L125 was not covered by tests
}
}

CompositeIndexFieldInfo supportedStarTree = getSupportedStarTree(this.context.getQueryShardContext());
if (supportedStarTree != null) {
if (parent != null && subAggregators.length == 0) {
Expand All @@ -132,21 +149,6 @@
throw new CollectionTerminatedException();
}
}
if (pointConverter != null) {
Number segMax = findLeafMaxValue(ctx.reader(), pointField, pointConverter);
if (segMax != null) {
/*
* There is no parent aggregator (see {@link AggregatorBase#getPointReaderOrNull}
* so the ordinal for the bucket is always 0.
*/
assert maxes.size() == 1;
double max = maxes.get(0);
max = Math.max(max, segMax.doubleValue());
maxes.set(0, max);
// the maximum value has been extracted, we don't need to collect hits on this segment.
throw new CollectionTerminatedException();
}
}

final BigArrays bigArrays = context.bigArrays();
final SortedNumericDoubleValues allValues = valuesSource.doubleValues(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@
if (valuesSource == null) {
return false;
}

if (pointConverter != null) {
Number segMin = findLeafMinValue(ctx.reader(), pointField, pointConverter);
if (segMin != null) {
/*
* There is no parent aggregator (see {@link MinAggregator#getPointReaderOrNull}
* so the ordinal for the bucket is always 0.
*/
double min = mins.get(0);
min = Math.min(min, segMin.doubleValue());
mins.set(0, min);

Check warning on line 122 in server/src/main/java/org/opensearch/search/aggregations/metrics/MinAggregator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/aggregations/metrics/MinAggregator.java#L120-L122

Added lines #L120 - L122 were not covered by tests
// the minimum value has been extracted, we don't need to collect hits on this segment.
return true;

Check warning on line 124 in server/src/main/java/org/opensearch/search/aggregations/metrics/MinAggregator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/aggregations/metrics/MinAggregator.java#L124

Added line #L124 was not covered by tests
}
}

CompositeIndexFieldInfo supportedStarTree = getSupportedStarTree(this.context.getQueryShardContext());
if (supportedStarTree != null) {
if (parent != null && subAggregators.length == 0) {
Expand All @@ -133,20 +149,6 @@
throw new CollectionTerminatedException();
}
}
if (pointConverter != null) {
Number segMin = findLeafMinValue(ctx.reader(), pointField, pointConverter);
if (segMin != null) {
/*
* There is no parent aggregator (see {@link MinAggregator#getPointReaderOrNull}
* so the ordinal for the bucket is always 0.
*/
double min = mins.get(0);
min = Math.min(min, segMin.doubleValue());
mins.set(0, min);
// the minimum value has been extracted, we don't need to collect hits on this segment.
throw new CollectionTerminatedException();
}
}

final BigArrays bigArrays = context.bigArrays();
final SortedNumericDoubleValues allValues = valuesSource.doubleValues(ctx);
Expand Down
Loading