Skip to content

Commit bd3c3df

Browse files
JonasKunzfzowl
authored andcommitted
Add BytesRefsFromBinaryBlockLoader (elastic#137095)
1 parent 2b3afe8 commit bd3c3df

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.index.mapper.blockloader.docvalues;
11+
12+
import org.apache.lucene.index.BinaryDocValues;
13+
import org.apache.lucene.index.LeafReaderContext;
14+
import org.apache.lucene.util.BytesRef;
15+
import org.elasticsearch.core.Nullable;
16+
17+
import java.io.IOException;
18+
19+
public class BytesRefsFromBinaryBlockLoader extends BlockDocValuesReader.DocValuesBlockLoader {
20+
21+
private final String fieldName;
22+
23+
public BytesRefsFromBinaryBlockLoader(String fieldName) {
24+
this.fieldName = fieldName;
25+
}
26+
27+
@Override
28+
public Builder builder(BlockFactory factory, int expectedCount) {
29+
return factory.bytesRefs(expectedCount);
30+
}
31+
32+
@Override
33+
public AllReader reader(LeafReaderContext context) throws IOException {
34+
BinaryDocValues docValues = context.reader().getBinaryDocValues(fieldName);
35+
return createReader(docValues);
36+
}
37+
38+
public static AllReader createReader(@Nullable BinaryDocValues docValues) {
39+
if (docValues == null) {
40+
return new ConstantNullsReader();
41+
}
42+
return new BytesRefsFromBinary(docValues);
43+
}
44+
45+
/**
46+
* Read BinaryDocValues with no additional structure in the BytesRefs.
47+
* Each BytesRef from the doc values maps directly to a value in the block loader.
48+
*/
49+
static class BytesRefsFromBinary extends BytesRefsFromCustomBinaryBlockLoader.AbstractBytesRefsFromBinary {
50+
51+
BytesRefsFromBinary(BinaryDocValues docValues) {
52+
super(docValues);
53+
}
54+
55+
@Override
56+
public void read(int doc, BytesRefBuilder builder) throws IOException {
57+
if (false == docValues.advanceExact(doc)) {
58+
builder.appendNull();
59+
return;
60+
}
61+
BytesRef bytes = docValues.binaryValue();
62+
builder.appendBytesRef(bytes);
63+
}
64+
65+
@Override
66+
public String toString() {
67+
return "BlockDocValuesReader.Bytes";
68+
}
69+
}
70+
}

x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/patterntext/PatternTextBlockLoader.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
package org.elasticsearch.xpack.logsdb.patterntext;
99

10-
import org.apache.lucene.index.BinaryDocValues;
1110
import org.apache.lucene.index.LeafReaderContext;
12-
import org.apache.lucene.util.BytesRef;
1311
import org.elasticsearch.index.mapper.blockloader.docvalues.BlockDocValuesReader;
14-
import org.elasticsearch.index.mapper.blockloader.docvalues.BytesRefsFromCustomBinaryBlockLoader;
12+
import org.elasticsearch.index.mapper.blockloader.docvalues.BytesRefsFromBinaryBlockLoader;
1513

1614
import java.io.IOException;
1715

@@ -31,34 +29,7 @@ public BytesRefBuilder builder(BlockFactory factory, int expectedCount) {
3129
@Override
3230
public AllReader reader(LeafReaderContext context) throws IOException {
3331
var docValues = docValuesSupplier.get(context.reader());
34-
if (docValues == null) {
35-
return new ConstantNullsReader();
36-
}
37-
return new BytesRefsFromBinary(docValues);
32+
return BytesRefsFromBinaryBlockLoader.createReader(docValues);
3833
}
3934

40-
/**
41-
* Read BinaryDocValues with no additional structure in the BytesRefs.
42-
* Each BytesRef from the doc values maps directly to a value in the block loader.
43-
*/
44-
public static class BytesRefsFromBinary extends BytesRefsFromCustomBinaryBlockLoader.AbstractBytesRefsFromBinary {
45-
public BytesRefsFromBinary(BinaryDocValues docValues) {
46-
super(docValues);
47-
}
48-
49-
@Override
50-
public void read(int doc, BytesRefBuilder builder) throws IOException {
51-
if (false == docValues.advanceExact(doc)) {
52-
builder.appendNull();
53-
return;
54-
}
55-
BytesRef bytes = docValues.binaryValue();
56-
builder.appendBytesRef(bytes);
57-
}
58-
59-
@Override
60-
public String toString() {
61-
return "BlockDocValuesReader.Bytes";
62-
}
63-
}
6435
}

0 commit comments

Comments
 (0)