Skip to content
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

Support retrieving doc values of unsigned long field #16543

Merged
merged 4 commits into from
Nov 1, 2024
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 @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Revert changes to upload remote state manifest using minimum codec version([#16403](https://github.com/opensearch-project/OpenSearch/pull/16403))
- Ensure index templates are not applied to system indices ([#16418](https://github.com/opensearch-project/OpenSearch/pull/16418))
- Remove resource usages object from search response headers ([#16532](https://github.com/opensearch-project/OpenSearch/pull/16532))
- Support retrieving doc values of unsigned long field ([#16543](https://github.com/opensearch-project/OpenSearch/pull/16543))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.lucene.sandbox.document.HalfFloatPoint;
import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.NumericUtils;
import org.opensearch.common.Numbers;
import org.opensearch.common.time.DateUtils;
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.index.fielddata.FieldData;
Expand Down Expand Up @@ -573,6 +574,28 @@ public final SortedBinaryDocValues getBytesValues() {
return FieldData.toUnsignedString(getLongValues());
}

@Override
public DocValueFetcher.Leaf getLeafValueFetcher(DocValueFormat format) {
SortedNumericDocValues values = getLongValues();
return new DocValueFetcher.Leaf() {
@Override
public boolean advanceExact(int docId) throws IOException {
return values.advanceExact(docId);
}

@Override
public int docValueCount() {
return values.docValueCount();
}

@Override
public Object nextValue() throws IOException {
final BigInteger value = Numbers.toUnsignedBigInteger(values.nextValue());
return format.format(value);
}
};
}

@Override
public long ramBytesUsed() {
return 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.opensearch.index.mapper.NumberFieldMapper.NumberFieldType;
import org.opensearch.index.mapper.NumberFieldMapper.NumberType;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.search.DocValueFormat;
import org.opensearch.search.MultiValueMode;
import org.opensearch.search.query.BitmapDocValuesQuery;
import org.junit.Before;
Expand Down Expand Up @@ -981,4 +982,28 @@ public void testBitmapQuery() throws IOException {
NumberFieldType finalFt = ft;
assertThrows(IllegalArgumentException.class, () -> finalFt.bitmapQuery(bitmap));
}

public void testFetchUnsignedLongDocValues() throws IOException {
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
Document doc = new Document();
final BigInteger expectedValue = randomUnsignedLong();
doc.add(new SortedNumericDocValuesField("ul", expectedValue.longValue()));
w.addDocument(doc);
try (DirectoryReader reader = DirectoryReader.open(w)) {
final NumberFieldType ft = new NumberFieldType("ul", NumberType.UNSIGNED_LONG);
IndexNumericFieldData fielddata = (IndexNumericFieldData) ft.fielddataBuilder(
"index",
() -> { throw new UnsupportedOperationException(); }
).build(null, null);
assertEquals(IndexNumericFieldData.NumericType.UNSIGNED_LONG, fielddata.getNumericType());
DocValueFetcher.Leaf fetcher = fielddata.load(reader.leaves().get(0)).getLeafValueFetcher(DocValueFormat.UNSIGNED_LONG);
assertTrue(fetcher.advanceExact(0));
assertEquals(1, fetcher.docValueCount());
final Object value = fetcher.nextValue();
assertTrue(value instanceof BigInteger);
assertEquals(expectedValue, value);
}
IOUtils.close(w, dir);
}
}
Loading