Skip to content

Commit 3534bd6

Browse files
committed
Simple bulk loading of compressed binary doc values
1 parent 666a8e6 commit 3534bd6

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,26 @@ private BinaryDocValues getCompressedBinary(BinaryEntry entry) throws IOExceptio
380380
public BytesRef binaryValue() throws IOException {
381381
return decoder.decode(doc, entry.numCompressedBlocks);
382382
}
383+
384+
@Override
385+
public BlockLoader.Block tryRead(
386+
BlockLoader.BlockFactory factory,
387+
BlockLoader.Docs docs,
388+
int offset,
389+
boolean nullsFiltered,
390+
BlockDocValuesReader.ToDouble toDouble,
391+
boolean toInt
392+
) throws IOException {
393+
int count = docs.count() - offset;
394+
try (var builder = factory.bytesRefs(count)) {
395+
for (int i = offset; i < docs.count(); i++) {
396+
doc = docs.get(i);
397+
var bytes = decoder.decode(doc, entry.numCompressedBlocks);
398+
builder.appendBytesRef(bytes);
399+
}
400+
return builder.build();
401+
}
402+
}
383403
};
384404
} else {
385405
// sparse

server/src/test/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesFormatTests.java

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -982,13 +982,9 @@ public void testOptionalColumnAtATimeReader() throws Exception {
982982
assertEquals(expectedGauge, actualGauge);
983983
}
984984
}
985-
986-
// TODO add bulk loading to compressed values so this is not necessary
987-
var block = (TestBlock) binaryFixedDV.tryRead(factory, docs, 0, random().nextBoolean(), null, false);
988-
if (isCompressed(config, binaryFixedField)) {
989-
assertNull(block);
990-
} else {
985+
{
991986
// bulk loading binary fixed length field:
987+
var block = (TestBlock) binaryFixedDV.tryRead(factory, docs, 0, random().nextBoolean(), null, false);
992988
assertNotNull(block);
993989
assertEquals(size, block.size());
994990
for (int j = 0; j < block.size(); j++) {
@@ -997,13 +993,9 @@ public void testOptionalColumnAtATimeReader() throws Exception {
997993
assertEquals(expected, actual);
998994
}
999995
}
1000-
1001-
// TODO add bulk loading to compressed values so this is not necessary
1002-
block = (TestBlock) binaryVariableDV.tryRead(factory, docs, 0, random().nextBoolean(), null, false);
1003-
if (isCompressed(config, binaryVariableField)) {
1004-
assertNull(block);
1005-
} else {
996+
{
1006997
// bulk loading binary variable length field:
998+
var block = (TestBlock) binaryVariableDV.tryRead(factory, docs, 0, random().nextBoolean(), null, false);
1007999
assertNotNull(block);
10081000
assertEquals(size, block.size());
10091001
for (int j = 0; j < block.size(); j++) {
@@ -1376,27 +1368,17 @@ public void testOptionalColumnAtATimeReaderWithSparseDocs() throws Exception {
13761368
{
13771369
var dv = getDenseBinaryValues(leafReader, binaryFixedField);
13781370
var block = (TestBlock) dv.tryRead(factory, docs, 0, random().nextBoolean(), null, false);
1379-
// TODO add bulk loading to compressed values so this is not necessary
1380-
if (isCompressed(config, binaryFixedField)) {
1381-
assertNull(block);
1382-
} else {
1383-
assertNotNull(block);
1384-
for (int i = 0; i < testDocs.size(); i++) {
1385-
assertThat(block.get(i), equalTo(binaryFixed[testDocs.get(i)]));
1386-
}
1371+
assertNotNull(block);
1372+
for (int i = 0; i < testDocs.size(); i++) {
1373+
assertThat(block.get(i), equalTo(binaryFixed[testDocs.get(i)]));
13871374
}
13881375
}
13891376
{
13901377
var dv = getDenseBinaryValues(leafReader, binaryVariableField);
13911378
var block = (TestBlock) dv.tryRead(factory, docs, 0, random().nextBoolean(), null, false);
1392-
// TODO add bulk loading to compressed values so this is not necessary
1393-
if (isCompressed(config, binaryVariableField)) {
1394-
assertNull(block);
1395-
} else {
1396-
assertNotNull(block);
1397-
for (int i = 0; i < testDocs.size(); i++) {
1398-
assertThat(block.get(i), equalTo(binaryVariable[testDocs.get(i)]));
1399-
}
1379+
assertNotNull(block);
1380+
for (int i = 0; i < testDocs.size(); i++) {
1381+
assertThat(block.get(i), equalTo(binaryVariable[testDocs.get(i)]));
14001382
}
14011383
}
14021384
}
@@ -1797,14 +1779,4 @@ public static BinaryDVCompressionMode randomBinaryCompressionMode() {
17971779
BinaryDVCompressionMode[] modes = BinaryDVCompressionMode.values();
17981780
return modes[random().nextInt(modes.length)];
17991781
}
1800-
1801-
private boolean isCompressed(IndexWriterConfig config, String field) {
1802-
if (config.getCodec() instanceof Elasticsearch92Lucene103Codec codec) {
1803-
if (codec.getDocValuesFormatForField(field) instanceof ES819TSDBDocValuesFormat format) {
1804-
return format.binaryDVCompressionMode != BinaryDVCompressionMode.NO_COMPRESS;
1805-
}
1806-
}
1807-
return false;
1808-
}
1809-
18101782
}

0 commit comments

Comments
 (0)