Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix indexing regression and bug fixes for grouping criteria. ([20145](https://github.com/opensearch-project/OpenSearch/pull/20145))
- LeafReader should not remove SubReaderWrappers incase IndexWriter encounters a non aborting Exception ([#20193](https://github.com/opensearch-project/OpenSearch/pull/20193))
- Fix Netty deprecation warnings in transport-reactor-netty4 module ([20429](https://github.com/opensearch-project/OpenSearch/pull/20429))
- Fix stats aggregation returning zero results with `size:0`. ([20427](https://github.com/opensearch-project/OpenSearch/pull/20427))

### Dependencies
- Bump `com.google.auth:google-auth-library-oauth2-http` from 1.38.0 to 1.41.0 ([#20183](https://github.com/opensearch-project/OpenSearch/pull/20183))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void collectRange(int min, int max) throws IOException {

double minimum = mins.get(0);
double maximum = maxes.get(0);
for (int doc = min; doc < maximum; doc++) {
for (int doc = min; doc < max; doc++) {
if (values.advanceExact(doc)) {
final int valuesCount = values.docValueCount();
counts.increment(0, valuesCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
Expand All @@ -55,6 +56,7 @@
import org.opensearch.script.ScriptType;
import org.opensearch.search.aggregations.AggregationBuilder;
import org.opensearch.search.aggregations.AggregatorTestCase;
import org.opensearch.search.aggregations.LeafBucketCollector;
import org.opensearch.search.aggregations.support.AggregationInspectionHelper;
import org.opensearch.search.aggregations.support.CoreValuesSourceType;
import org.opensearch.search.aggregations.support.ValuesSourceType;
Expand Down Expand Up @@ -484,4 +486,36 @@ protected ScriptService getMockScriptService() {
final Map<String, ScriptEngine> engines = singletonMap(engine.getType(), engine);
return new ScriptService(Settings.EMPTY, engines, ScriptModule.CORE_CONTEXTS);
}

public void testCollectRange() throws IOException {
final MappedFieldType ft = new NumberFieldMapper.NumberFieldType("field", NumberType.LONG);
try (Directory directory = newDirectory(); RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
final SimpleStatsAggregator expected = new SimpleStatsAggregator();
int numDocs = randomIntBetween(10, 50);
for (int i = 0; i < numDocs; i++) {
long value = randomLongBetween(-100, 100);
indexWriter.addDocument(singleton(new SortedNumericDocValuesField(ft.name(), value)));
expected.add(value);
}
try (IndexReader reader = indexWriter.getReader()) {
IndexSearcher searcher = newIndexSearcher(reader);
StatsAggregationBuilder builder = stats("_name").field(ft.name());
StatsAggregator aggregator = createAggregator(builder, searcher, ft);
aggregator.preCollection();
// Directly call collectRange on each leaf to test with size:0 queries
for (LeafReaderContext leaf : reader.leaves()) {
LeafBucketCollector leafCollector = aggregator.getLeafCollector(leaf);
leafCollector.collectRange(0, leaf.reader().maxDoc());
}
aggregator.postCollection();
InternalStats stats = (InternalStats) aggregator.buildTopLevel();
assertEquals(expected.count, stats.getCount(), 0);
assertEquals(expected.sum, stats.getSum(), TOLERANCE);
assertEquals(expected.min, stats.getMin(), 0);
assertEquals(expected.max, stats.getMax(), 0);
assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
assertTrue(AggregationInspectionHelper.hasValue(stats));
}
}
}
}
Loading