Skip to content

Commit adfca29

Browse files
committed
bulk load dense binary doc values.
1 parent 511b032 commit adfca29

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesProducer.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ public BytesRef binaryValue() throws IOException {
208208
bytesSlice.readBytes((long) doc * length, bytes.bytes, 0, length);
209209
return bytes;
210210
}
211+
212+
@Override
213+
public BlockLoader.Block tryRead(
214+
BlockLoader.BlockFactory factory,
215+
BlockLoader.Docs docs,
216+
int offset,
217+
boolean nullsFiltered,
218+
BlockDocValuesReader.ToDouble toDouble,
219+
boolean toInt
220+
) throws IOException {
221+
int count = docs.count() - offset;
222+
try (var builder = factory.bytesRefs(count)) {
223+
for (int i = offset; i < docs.count(); i++) {
224+
doc = docs.get(i);
225+
bytesSlice.readBytes((long) doc * length, bytes.bytes, 0, length);
226+
builder.appendBytesRef(bytes);
227+
}
228+
return builder.build();
229+
}
230+
}
211231
};
212232
} else {
213233
// variable length
@@ -223,6 +243,28 @@ public BytesRef binaryValue() throws IOException {
223243
bytesSlice.readBytes(startOffset, bytes.bytes, 0, bytes.length);
224244
return bytes;
225245
}
246+
247+
@Override
248+
public BlockLoader.Block tryRead(
249+
BlockLoader.BlockFactory factory,
250+
BlockLoader.Docs docs,
251+
int offset,
252+
boolean nullsFiltered,
253+
BlockDocValuesReader.ToDouble toDouble,
254+
boolean toInt
255+
) throws IOException {
256+
int count = docs.count() - offset;
257+
try (var builder = factory.bytesRefs(count)) {
258+
for (int i = offset; i < docs.count(); i++) {
259+
doc = docs.get(i);
260+
long startOffset = addresses.get(doc);
261+
bytes.length = (int) (addresses.get(doc + 1L) - startOffset);
262+
bytesSlice.readBytes(startOffset, bytes.bytes, 0, bytes.length);
263+
builder.appendBytesRef(bytes);
264+
}
265+
return builder.build();
266+
}
267+
}
226268
};
227269
}
228270
} else {
@@ -267,7 +309,7 @@ public BytesRef binaryValue() throws IOException {
267309
}
268310
}
269311

270-
private abstract static class DenseBinaryDocValues extends BinaryDocValues {
312+
private abstract static class DenseBinaryDocValues extends BinaryDocValues implements BlockLoader.OptionalColumnAtATimeReader {
271313

272314
final int maxDoc;
273315
int doc = -1;

server/src/main/java/org/elasticsearch/index/mapper/BlockDocValuesReader.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,17 @@ public BytesRefsFromBinary(BinaryDocValues docValues) {
10321032
super(docValues);
10331033
}
10341034

1035+
@Override
1036+
public BlockLoader.Block read(BlockFactory factory, Docs docs, int offset, boolean nullsFiltered) throws IOException {
1037+
if (docValues instanceof BlockLoader.OptionalColumnAtATimeReader direct) {
1038+
BlockLoader.Block block = direct.tryRead(factory, docs, offset, nullsFiltered, null, false);
1039+
if (block != null) {
1040+
return block;
1041+
}
1042+
}
1043+
return super.read(factory, docs, offset, nullsFiltered);
1044+
}
1045+
10351046
@Override
10361047
void read(int doc, BytesRefBuilder builder) throws IOException {
10371048
if (false == docValues.advanceExact(doc)) {

0 commit comments

Comments
 (0)