From 89de2f857793bd2261cd9cbfc713a61ab31fa131 Mon Sep 17 00:00:00 2001 From: Sandesh Kumar Date: Mon, 30 Sep 2024 23:04:10 -0700 Subject: [PATCH] avg aggregator fix, iterators refactoring Signed-off-by: Sandesh Kumar --- .../datacube/startree/utils/StarTreeQueryHelper.java | 2 +- .../startree/utils/iterator/StarTreeValuesIterator.java | 2 +- .../opensearch/search/aggregations/metrics/AvgAggregator.java | 4 +--- .../java/org/opensearch/search/startree/StarTreeFilter.java | 4 +++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java index a87f6e5f94406..a5bc3327bfb09 100644 --- a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java +++ b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/StarTreeQueryHelper.java @@ -211,7 +211,7 @@ public static LeafBucketCollector getStarTreeLeafCollector( // Iterate over the FixedBitSet for (int bit = matchedDocIds.nextSetBit(0); bit != -1; bit = (bit + 1 < numBits) ? matchedDocIds.nextSetBit(bit + 1) : -1) { // Advance to the entryId in the valuesIterator - if (!valuesIterator.advanceExact(bit)) { + if (valuesIterator.advanceExact(bit) == false) { continue; // Skip if no more entries } diff --git a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/iterator/StarTreeValuesIterator.java b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/iterator/StarTreeValuesIterator.java index 454e5b393973f..32866f3e50092 100644 --- a/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/iterator/StarTreeValuesIterator.java +++ b/server/src/main/java/org/opensearch/index/compositeindex/datacube/startree/utils/iterator/StarTreeValuesIterator.java @@ -21,7 +21,7 @@ * @opensearch.experimental */ @ExperimentalApi -public class StarTreeValuesIterator { +public abstract class StarTreeValuesIterator { public static final int NO_MORE_ENTRIES = Integer.MAX_VALUE; protected final DocIdSetIterator docIdSetIterator; diff --git a/server/src/main/java/org/opensearch/search/aggregations/metrics/AvgAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/metrics/AvgAggregator.java index de0fde8df58da..49380fdadb175 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/metrics/AvgAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/metrics/AvgAggregator.java @@ -46,7 +46,6 @@ import org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeQueryHelper; import org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeUtils; import org.opensearch.index.compositeindex.datacube.startree.utils.iterator.SortedNumericStarTreeValuesIterator; -import org.opensearch.index.compositeindex.datacube.startree.utils.iterator.StarTreeValuesIterator; import org.opensearch.index.fielddata.SortedNumericDoubleValues; import org.opensearch.search.DocValueFormat; import org.opensearch.search.aggregations.Aggregator; @@ -177,8 +176,7 @@ public LeafBucketCollector getStarTreeLeafCollector(LeafReaderContext ctx, LeafB // Iterate over the FixedBitSet for (int bit = matchedDocIds.nextSetBit(0); bit != -1; bit = bit + 1 < numBits ? matchedDocIds.nextSetBit(bit + 1) : -1) { // Advance to the bit (entryId) in the valuesIterator - if (sumValuesIterator.advance(bit) == StarTreeValuesIterator.NO_MORE_ENTRIES - || countValueIterator.advance(bit) == StarTreeValuesIterator.NO_MORE_ENTRIES) { + if ((sumValuesIterator.advanceExact(bit) && countValueIterator.advanceExact(bit)) == false) { continue; // Skip if no more entries } diff --git a/server/src/main/java/org/opensearch/search/startree/StarTreeFilter.java b/server/src/main/java/org/opensearch/search/startree/StarTreeFilter.java index dcc5bff8a7887..79a01d5230106 100644 --- a/server/src/main/java/org/opensearch/search/startree/StarTreeFilter.java +++ b/server/src/main/java/org/opensearch/search/startree/StarTreeFilter.java @@ -62,7 +62,9 @@ public FixedBitSet getStarTreeResult() throws IOException { // Initialize FixedBitSet with size maxMatchedDoc + 1 FixedBitSet bitSet = new FixedBitSet(starTreeResult.maxMatchedDoc + 1); - StarTreeValuesIterator starTreeValuesIterator = new StarTreeValuesIterator(starTreeResult._matchedDocIds.build().iterator()); + SortedNumericStarTreeValuesIterator starTreeValuesIterator = new SortedNumericStarTreeValuesIterator( + starTreeResult._matchedDocIds.build().iterator() + ); // No matches, return an empty FixedBitSet if (starTreeResult.maxMatchedDoc == -1) {