From 06a2ba394b29e86f12d995028108cc21443c4bba Mon Sep 17 00:00:00 2001 From: Sandesh Kumar Date: Thu, 30 Jan 2025 02:57:09 -0800 Subject: [PATCH] apply aggreagtion pre-computation unifying changes Signed-off-by: Sandesh Kumar --- .../GlobalOrdinalsStringTermsAggregator.java | 14 +++++--------- .../bucket/terms/NumericTermsAggregator.java | 16 ++++++++-------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java index b7054b3ec4994..2a7c1cb857c55 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java @@ -40,7 +40,6 @@ import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.search.CollectionTerminatedException; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Weight; import org.apache.lucene.util.ArrayUtil; @@ -244,6 +243,10 @@ protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws (ord, docCount) -> incrementBucketDocCount(collectionStrategy.globalOrdToBucketOrd(0, ord), docCount) ); } + CompositeIndexFieldInfo supportedStarTree = StarTreeQueryHelper.getSupportedStarTree(this.context.getQueryShardContext()); + if (supportedStarTree != null) { + return preComputeWithStarTree(ctx, supportedStarTree); + } return false; } @@ -251,14 +254,6 @@ protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException { SortedSetDocValues globalOrds = valuesSource.globalOrdinalsValues(ctx); collectionStrategy.globalOrdsReady(globalOrds); - globalOperator = valuesSource.globalOrdinalsMapping(ctx); - - CompositeIndexFieldInfo supportedStarTree = StarTreeQueryHelper.getSupportedStarTree(this.context.getQueryShardContext()); - if (supportedStarTree != null) { - if (preComputeWithStarTree(ctx, supportedStarTree) == true) { - throw new CollectionTerminatedException(); - } - } SortedDocValues singleValues = DocValues.unwrapSingleton(globalOrds); if (singleValues != null) { @@ -398,6 +393,7 @@ public void collectStarTreeEntry(int starTreeEntry, long owningBucketOrd) throws } private boolean preComputeWithStarTree(LeafReaderContext ctx, CompositeIndexFieldInfo supportedStarTree) throws IOException { + globalOperator = valuesSource.globalOrdinalsMapping(ctx); StarTreeBucketCollector starTreeBucketCollector = getStarTreeBucketCollector(ctx, supportedStarTree, null); FixedBitSet matchingDocsBitSet = starTreeBucketCollector.getMatchingDocsBitSet(); diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregator.java index d067ee19ed31c..60c4c6bb2809c 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregator.java @@ -34,7 +34,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; -import org.apache.lucene.search.CollectionTerminatedException; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.FixedBitSet; @@ -134,13 +133,6 @@ public ScoreMode scoreMode() { @Override public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException { - CompositeIndexFieldInfo supportedStarTree = StarTreeQueryHelper.getSupportedStarTree(this.context.getQueryShardContext()); - if (supportedStarTree != null) { - if (preComputeWithStarTree(ctx, supportedStarTree) == true) { - throw new CollectionTerminatedException(); - } - } - SortedNumericDocValues values = resultStrategy.getValues(ctx); return resultStrategy.wrapCollector(new LeafBucketCollectorBase(sub, values) { @Override @@ -170,6 +162,14 @@ public void collect(int doc, long owningBucketOrd) throws IOException { }); } + protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException { + CompositeIndexFieldInfo supportedStarTree = StarTreeQueryHelper.getSupportedStarTree(this.context.getQueryShardContext()); + if (supportedStarTree != null) { + return preComputeWithStarTree(ctx, supportedStarTree); + } + return false; + } + public StarTreeBucketCollector getStarTreeBucketCollector( LeafReaderContext ctx, CompositeIndexFieldInfo starTree,