Skip to content

[Aggregations] Optimize singleton handling in GlobalOrdinalValuesSource #17740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed
- Migrate BC libs to their FIPS counterparts ([#14912](https://github.com/opensearch-project/OpenSearch/pull/14912))
- Increase the floor segment size to 16MB ([#17699](https://github.com/opensearch-project/OpenSearch/pull/17699))
- Unwrap singleton DocValues in global ordinal value source of composite histogram aggregation ([#17740](https://github.com/opensearch-project/OpenSearch/pull/17740))
- Unwrap singleton DocValues in date histogram aggregation. ([#17643](https://github.com/opensearch-project/OpenSearch/pull/17643))
- Introduce 512 byte limit to search and ingest pipeline IDs ([#17786](https://github.com/opensearch-project/OpenSearch/pull/17786))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@

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

import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
Expand Down Expand Up @@ -171,6 +173,26 @@ LeafBucketCollector getLeafCollector(LeafReaderContext context, LeafBucketCollec
if (lookup == null) {
initLookup(dvs);
}

// unwrapSingleton() returns non-null only if the field is single-valued
final SortedDocValues singleton = DocValues.unwrapSingleton(dvs);

// Direct ordinal access for single-valued fields
if (singleton != null) {
return new LeafBucketCollector() {
@Override
public void collect(int doc, long bucket) throws IOException {
if (singleton.advanceExact(doc)) {
currentValue = singleton.ordValue();
next.collect(doc, bucket);
} else if (missingBucket) {
currentValue = -1;
next.collect(doc, bucket);
}
}
};
}

return new LeafBucketCollector() {
@Override
public void collect(int doc, long bucket) throws IOException {
Expand Down
Loading