Skip to content

Commit 3823169

Browse files
shreyah963bowenlan-amznjainankitk
authored
[Aggregations] Optimize singleton handling in GlobalOrdinalValuesSource (#17740)
* added singleton optimization path to globalordinalvaluesource Signed-off-by: shreyah963 <[email protected]> * enabled remote debugging Signed-off-by: shreyah963 <[email protected]> * Removed the minimum cap to handle larger ordinal values Signed-off-by: shreyah963 <[email protected]> * emove redundant singleton optimization state from SingleDimensionValuesSource and simplify the optimization logic in GlobalOrdinalValuesSource. The singleton optimization is now only applied when DocValues.unwrapSingleton() succeeds, preventing array index out of bounds errors with high cardinality fields. Signed-off-by: shreyah963 <[email protected]> * removed redundant initialization Signed-off-by: shreyah963 <[email protected]> * reverted the array allocation in the constructer to its original form Signed-off-by: shreyah963 <[email protected]> * [Docs] Add detailed comments to GlobalOrdinalValuesSource collector Signed-off-by: shreyah963 <[email protected]> * Remote redundant imports and disable remote debugging Signed-off-by: shreyah963 <[email protected]> * replaced wildcard import with only necessary imports Signed-off-by: shreyah963 <[email protected]> * Update CHANGELOG.md Signed-off-by: shreyah963 <[email protected]> * Update CHANGELOG.md Co-authored-by: bowenlan-amzn <[email protected]> Signed-off-by: shreyah963 <[email protected]> * Remove redundant comments from GlobalOrdinalValuesSource Signed-off-by: shreyah963 <[email protected]> --------- Signed-off-by: shreyah963 <[email protected]> Signed-off-by: Ankit Jain <[email protected]> Co-authored-by: bowenlan-amzn <[email protected]> Co-authored-by: Ankit Jain <[email protected]>
1 parent 0d86ac1 commit 3823169

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3131
### Changed
3232
- Migrate BC libs to their FIPS counterparts ([#14912](https://github.com/opensearch-project/OpenSearch/pull/14912))
3333
- Increase the floor segment size to 16MB ([#17699](https://github.com/opensearch-project/OpenSearch/pull/17699))
34+
- Unwrap singleton DocValues in global ordinal value source of composite histogram aggregation ([#17740](https://github.com/opensearch-project/OpenSearch/pull/17740))
3435
- Unwrap singleton DocValues in date histogram aggregation. ([#17643](https://github.com/opensearch-project/OpenSearch/pull/17643))
3536
- Introduce 512 byte limit to search and ingest pipeline IDs ([#17786](https://github.com/opensearch-project/OpenSearch/pull/17786))
3637

server/src/main/java/org/opensearch/search/aggregations/bucket/composite/GlobalOrdinalValuesSource.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232

3333
package org.opensearch.search.aggregations.bucket.composite;
3434

35+
import org.apache.lucene.index.DocValues;
3536
import org.apache.lucene.index.IndexReader;
3637
import org.apache.lucene.index.LeafReaderContext;
38+
import org.apache.lucene.index.SortedDocValues;
3739
import org.apache.lucene.index.SortedSetDocValues;
3840
import org.apache.lucene.search.MatchAllDocsQuery;
3941
import org.apache.lucene.search.Query;
@@ -171,6 +173,26 @@ LeafBucketCollector getLeafCollector(LeafReaderContext context, LeafBucketCollec
171173
if (lookup == null) {
172174
initLookup(dvs);
173175
}
176+
177+
// unwrapSingleton() returns non-null only if the field is single-valued
178+
final SortedDocValues singleton = DocValues.unwrapSingleton(dvs);
179+
180+
// Direct ordinal access for single-valued fields
181+
if (singleton != null) {
182+
return new LeafBucketCollector() {
183+
@Override
184+
public void collect(int doc, long bucket) throws IOException {
185+
if (singleton.advanceExact(doc)) {
186+
currentValue = singleton.ordValue();
187+
next.collect(doc, bucket);
188+
} else if (missingBucket) {
189+
currentValue = -1;
190+
next.collect(doc, bucket);
191+
}
192+
}
193+
};
194+
}
195+
174196
return new LeafBucketCollector() {
175197
@Override
176198
public void collect(int doc, long bucket) throws IOException {

0 commit comments

Comments
 (0)