Skip to content

Commit

Permalink
Add segment match all guard for range aggregator
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Aug 16, 2024
1 parent 374099e commit 490d442
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public static boolean isCompositeAggRewriteable(CompositeValuesSourceConfig[] so
return sourceConfigs.length == 1 && sourceConfigs[0].valuesSource() instanceof RoundingValuesSource;
}

private static boolean segmentMatchAll(SearchContext ctx, LeafReaderContext leafCtx) throws IOException {
public static boolean segmentMatchAll(SearchContext ctx, LeafReaderContext leafCtx) throws IOException {
Weight weight = ctx.searcher().createWeight(ctx.query(), ScoreMode.COMPLETE_NO_SCORES, 1f);
return weight != null && weight.count(leafCtx) == leafCtx.reader().numDocs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.function.BiConsumer;

import static org.opensearch.core.xcontent.ConstructingObjectParser.optionalConstructorArg;
import static org.opensearch.search.aggregations.bucket.FastFilterRewriteHelper.segmentMatchAll;

/**
* Aggregate all docs that match given ranges.
Expand Down Expand Up @@ -298,12 +299,14 @@ public ScoreMode scoreMode() {

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
boolean optimized = fastFilterContext.tryFastFilterAggregation(
ctx,
this::incrementBucketDocCount,
(activeIndex) -> subBucketOrdinal(0, (int) activeIndex)
);
if (optimized) throw new CollectionTerminatedException();
if (segmentMatchAll(context, ctx)
&& fastFilterContext.tryFastFilterAggregation(
ctx,
this::incrementBucketDocCount,
(activeIndex) -> subBucketOrdinal(0, (int) activeIndex)
)) {
throw new CollectionTerminatedException();
}

final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
return new LeafBucketCollectorBase(sub, values) {
Expand Down

0 comments on commit 490d442

Please sign in to comment.