Skip to content

Commit 23874ce

Browse files
committed
more
1 parent 132149d commit 23874ce

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,14 +1403,8 @@ public BlockLoader.Block tryRead(
14031403
boolean nullsFiltered,
14041404
BlockDocValuesReader.ToDouble toDouble
14051405
) throws IOException {
1406-
if (toDouble != null) {
1407-
try (BlockLoader.SingletonDoubleBuilder builder = factory.singletonDoubles(docs.count() - offset)) {
1408-
SingletonLongToDoubleDelegate delegate = new SingletonLongToDoubleDelegate(builder, toDouble);
1409-
return tryRead(delegate, docs, offset);
1410-
}
1411-
}
1412-
try (BlockLoader.SingletonLongBuilder builder = factory.singletonLongs(docs.count() - offset)) {
1413-
return tryRead(builder, docs, offset);
1406+
try (var longs = singletonLongs(factory, toDouble, docs.count() - offset)) {
1407+
return tryRead(longs, docs, offset);
14141408
}
14151409
}
14161410

@@ -1564,9 +1558,8 @@ public BlockLoader.Block tryRead(
15641558
if (valueCount != docs.count()) {
15651559
return null;
15661560
}
1567-
try (var doubles = factory.singletonDoubles(valueCount)) {
1568-
var longs = new SingletonLongToDoubleDelegate(doubles, toDouble);
1569-
for (int i = 0; i < valueCount; ) {
1561+
try (var longs = singletonLongs(factory, toDouble, valueCount)) {
1562+
for (int i = 0; i < valueCount;) {
15701563
final int index = firstIndex + i;
15711564
final int blockIndex = index >>> ES819TSDBDocValuesFormat.NUMERIC_BLOCK_SHIFT;
15721565
final int blockStartIndex = index & ES819TSDBDocValuesFormat.NUMERIC_BLOCK_MASK;
@@ -1583,7 +1576,7 @@ public BlockLoader.Block tryRead(
15831576
longs.appendLongs(currentBlock, blockStartIndex, count);
15841577
i += count;
15851578
}
1586-
return doubles.build();
1579+
return longs.build();
15871580
}
15881581
}
15891582
};
@@ -1881,6 +1874,18 @@ public BlockLoader.Builder endPositionEntry() {
18811874
public void close() {}
18821875
}
18831876

1877+
static BlockLoader.SingletonLongBuilder singletonLongs(
1878+
BlockLoader.BlockFactory factory,
1879+
BlockDocValuesReader.ToDouble toDouble,
1880+
int valueCount
1881+
) {
1882+
if (toDouble != null) {
1883+
return new SingletonLongToDoubleDelegate(factory.singletonDoubles(valueCount), toDouble);
1884+
} else {
1885+
return factory.singletonLongs(valueCount);
1886+
}
1887+
}
1888+
18841889
// Block builder that consumes long values and converts them to double using the provided converter function.
18851890
static final class SingletonLongToDoubleDelegate implements BlockLoader.SingletonLongBuilder {
18861891
private final BlockLoader.SingletonDoubleBuilder doubleBuilder;
@@ -1929,7 +1934,9 @@ public BlockLoader.Builder endPositionEntry() {
19291934
}
19301935

19311936
@Override
1932-
public void close() {}
1937+
public void close() {
1938+
doubleBuilder.close();
1939+
}
19331940
}
19341941

19351942
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/read/SingletonLongBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public long estimatedBytes() {
6565

6666
@Override
6767
public Block build() {
68+
if (values.length != count) {
69+
throw new IllegalStateException("expected [" + values.length + "] values but got [" + count + "]");
70+
}
6871
return blockFactory.newLongArrayVector(values, count).asBlock();
6972
}
7073

0 commit comments

Comments
 (0)