Skip to content

Commit 6e29516

Browse files
authored
ESQL: Implement coalesce for exponential histograms (#137897)
1 parent 2b3613b commit 6e29516

File tree

12 files changed

+415
-31
lines changed

12 files changed

+415
-31
lines changed

x-pack/plugin/esql/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ tasks.named('stringTemplates').configure {
468468
var doubleProperties = prop("Double", "Double", "double", "DOUBLE", "Double.BYTES", "DoubleArray")
469469
var bytesRefProperties = prop("BytesRef", "BytesRef", "BytesRef", "BYTES_REF", "org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_REF", "")
470470
var booleanProperties = prop("Boolean", "Boolean", "boolean", "BOOLEAN", "Byte.BYTES", "BitArray")
471+
var expHistoProperties = prop("ExponentialHistogram", "ExponentialHistogram", "ExponentialHistogram", "EXPONENTIAL_HISTOGRAM", "", "")
471472

472473
File inInputFile = file("src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/X-InEvaluator.java.st")
473474
template {
@@ -532,6 +533,11 @@ tasks.named('stringTemplates').configure {
532533
it.inputFile = coalesceInputFile
533534
it.outputFile = "org/elasticsearch/xpack/esql/expression/function/scalar/nulls/CoalesceBytesRefEvaluator.java"
534535
}
536+
template {
537+
it.properties = expHistoProperties
538+
it.inputFile = coalesceInputFile
539+
it.outputFile = "org/elasticsearch/xpack/esql/expression/function/scalar/nulls/CoalesceExponentialHistogramEvaluator.java"
540+
}
535541

536542
File roundToInput = file("src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st")
537543
template {

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ExponentialHistogramBlock.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.apache.lucene.util.BytesRef;
1111
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;
12+
import org.elasticsearch.index.mapper.BlockLoader;
1213

1314
/**
1415
* A block that holds {@link ExponentialHistogram} values.
@@ -93,6 +94,20 @@ static boolean equals(ExponentialHistogramBlock blockA, ExponentialHistogramBloc
9394
};
9495
}
9596

97+
/**
98+
* Builder for {@link ExponentialHistogramBlock}
99+
*/
100+
sealed interface Builder extends Block.Builder, BlockLoader.ExponentialHistogramBuilder permits ExponentialHistogramBlockBuilder {
101+
102+
/**
103+
* Copy the values in {@code block} from the given positon into this builder.
104+
*/
105+
Builder copyFrom(ExponentialHistogramBlock block, int position);
106+
107+
@Override
108+
ExponentialHistogramBlock build();
109+
}
110+
96111
/**
97112
* Abstraction to use for writing individual values via {@link #serializeExponentialHistogram(int, SerializedOutput, BytesRef)}.
98113
*/

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ExponentialHistogramBlockBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import java.io.IOException;
1919

20-
public class ExponentialHistogramBlockBuilder implements Block.Builder, BlockLoader.ExponentialHistogramBuilder {
20+
public final class ExponentialHistogramBlockBuilder implements ExponentialHistogramBlock.Builder {
2121

2222
private final DoubleBlock.Builder minimaBuilder;
2323
private final DoubleBlock.Builder maximaBuilder;
@@ -221,6 +221,12 @@ public ExponentialHistogramBlockBuilder copyFrom(Block block, int beginInclusive
221221
return this;
222222
}
223223

224+
@Override
225+
public ExponentialHistogramBlock.Builder copyFrom(ExponentialHistogramBlock block, int position) {
226+
copyFrom(block, position, position + 1);
227+
return this;
228+
}
229+
224230
@Override
225231
public ExponentialHistogramBlockBuilder mvOrdering(Block.MvOrdering mvOrdering) {
226232
assert mvOrdering == Block.MvOrdering.UNORDERED
@@ -238,4 +244,5 @@ public long estimatedBytes() {
238244
public void close() {
239245
Releasables.close(minimaBuilder, maximaBuilder, sumsBuilder, valueCountsBuilder, zeroThresholdsBuilder, encodedHistogramsBuilder);
240246
}
247+
241248
}

x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/nulls/CoalesceBooleanEvaluator.java

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/nulls/CoalesceBytesRefEvaluator.java

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/nulls/CoalesceDoubleEvaluator.java

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)