Skip to content

Commit ffda262

Browse files
committed
added binary doc values fetcher
Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
1 parent 90f73e2 commit ffda262

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.index.mapper;
10+
11+
import org.apache.lucene.index.BinaryDocValues;
12+
import org.apache.lucene.index.LeafReader;
13+
14+
import java.io.IOException;
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
public class BinaryDocValuesFetcher extends FieldValueFetcher {
19+
20+
public BinaryDocValuesFetcher(MappedFieldType mappedFieldType, String simpleName) {
21+
super(simpleName);
22+
this.mappedFieldType = mappedFieldType;
23+
}
24+
25+
@Override
26+
public List<Object> fetch(LeafReader reader, int docId) throws IOException {
27+
List<Object> values = new ArrayList<>();
28+
try {
29+
final BinaryDocValues binaryDocValues = reader.getBinaryDocValues(mappedFieldType.name());
30+
if (binaryDocValues == null || !binaryDocValues.advanceExact(docId)) {
31+
return values;
32+
}
33+
values.add(binaryDocValues.binaryValue());
34+
} catch (IOException e) {
35+
throw new IOException("Failed to read doc values for document " + docId + " in field " + mappedFieldType.name(), e);
36+
}
37+
return values;
38+
}
39+
}

server/src/main/java/org/opensearch/index/mapper/WildcardFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ protected void canDeriveSourceInternal() {
930930
*/
931931
@Override
932932
protected DerivedFieldGenerator derivedFieldGenerator() {
933-
return new DerivedFieldGenerator(mappedFieldType, new SortedSetDocValuesFetcher(mappedFieldType, simpleName()) {
933+
return new DerivedFieldGenerator(mappedFieldType, new BinaryDocValuesFetcher(mappedFieldType, simpleName()) {
934934
@Override
935935
public Object convert(Object value) {
936936
if (value == null) {

0 commit comments

Comments
 (0)