Skip to content

Commit 43831ab

Browse files
committed
avoid buffer
1 parent b3b9dbb commit 43831ab

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,6 @@ static BlockLoader.SingletonLongBuilder singletonLongs(
18971897
static final class SingletonLongToDoubleDelegate implements BlockLoader.SingletonLongBuilder {
18981898
private final BlockLoader.SingletonDoubleBuilder doubleBuilder;
18991899
private final BlockDocValuesReader.ToDouble toDouble;
1900-
private final double[] buffer = new double[ES819TSDBDocValuesFormat.NUMERIC_BLOCK_SIZE];
19011900

19021901
// The passed builder is used to store the converted double values and produce the final block containing them.
19031902
SingletonLongToDoubleDelegate(BlockLoader.SingletonDoubleBuilder doubleBuilder, BlockDocValuesReader.ToDouble toDouble) {
@@ -1912,11 +1911,7 @@ public BlockLoader.SingletonLongBuilder appendLong(long value) {
19121911

19131912
@Override
19141913
public BlockLoader.SingletonLongBuilder appendLongs(long[] values, int from, int length) {
1915-
assert length <= buffer.length : "length " + length + " > " + buffer.length;
1916-
for (int i = 0; i < length; i++) {
1917-
buffer[i] = toDouble.convert(values[from + i]);
1918-
}
1919-
doubleBuilder.appendDoubles(buffer, 0, length);
1914+
doubleBuilder.appendLongs(toDouble, values, from, length);
19201915
return this;
19211916
}
19221917

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ interface SingletonDoubleBuilder extends Builder {
575575
SingletonDoubleBuilder appendDouble(double value);
576576

577577
SingletonDoubleBuilder appendDoubles(double[] values, int from, int length);
578+
579+
SingletonDoubleBuilder appendLongs(BlockDocValuesReader.ToDouble toDouble, long[] values, int from, int length);
578580
}
579581

580582
interface LongBuilder extends Builder {

test/framework/src/main/java/org/elasticsearch/index/mapper/TestBlock.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,20 @@ public BlockLoader.SingletonDoubleBuilder appendDouble(double value) {
286286
return this;
287287
}
288288

289+
@Override
290+
public BlockLoader.SingletonDoubleBuilder appendLongs(
291+
BlockDocValuesReader.ToDouble toDouble,
292+
long[] longValues,
293+
int from,
294+
int length
295+
) {
296+
for (int i = 0; i < length; i++) {
297+
values[count + i] = toDouble.convert(longValues[from + i]);
298+
}
299+
this.count += length;
300+
return this;
301+
}
302+
289303
@Override
290304
public BlockLoader.Builder appendNull() {
291305
throw new UnsupportedOperationException();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.compute.data.Block;
1111
import org.elasticsearch.compute.data.BlockFactory;
1212
import org.elasticsearch.core.Releasable;
13+
import org.elasticsearch.index.mapper.BlockDocValuesReader;
1314
import org.elasticsearch.index.mapper.BlockLoader;
1415

1516
/**
@@ -84,6 +85,15 @@ public BlockLoader.SingletonDoubleBuilder appendDoubles(double[] values, int fro
8485
return this;
8586
}
8687

88+
@Override
89+
public BlockLoader.SingletonDoubleBuilder appendLongs(BlockDocValuesReader.ToDouble toDouble, long[] longValues, int from, int length) {
90+
for (int i = 0; i < length; i++) {
91+
values[count + i] = toDouble.convert(longValues[from + i]);
92+
}
93+
this.count += length;
94+
return this;
95+
}
96+
8797
@Override
8898
public void close() {
8999
blockFactory.adjustBreaker(-valuesSize(values.length));

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/lucene/read/SingletonDoubleBuilderTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ private void testRead(BlockFactory factory) throws IOException {
7272
double value = Double.longBitsToDouble(docValues.longValue());
7373
if (randomBoolean()) {
7474
builder.appendDoubles(new double[] { value }, 0, 1);
75+
} else if (randomBoolean()) {
76+
builder.appendLongs(Double::longBitsToDouble, new long[] { docValues.longValue() }, 0, 1);
7577
} else {
7678
builder.appendDouble(value);
7779
}

0 commit comments

Comments
 (0)