Skip to content

Commit bb68bd8

Browse files
authored
ES|QL: Implement percentiles aggregation for tdigest (elastic#139301)
1 parent b166aac commit bb68bd8

File tree

37 files changed

+1734
-88
lines changed

37 files changed

+1734
-88
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ Block buildExponentialHistogramBlockDirect(
688688
);
689689

690690
Block buildTDigestBlockDirect(Block encodedDigests, Block minima, Block maxima, Block sums, Block valueCounts);
691+
692+
TDigestBuilder tdigestBlockBuilder(int count);
691693
}
692694

693695
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,12 @@ public BlockLoader.Block buildTDigestBlockDirect(
553553

554554
return new TestBlock(values);
555555
}
556+
557+
@Override
558+
public BlockLoader.TDigestBuilder tdigestBlockBuilder(int count) {
559+
// TODO: implement when needed
560+
throw new UnsupportedOperationException();
561+
}
556562
};
557563
}
558564

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/TDigestBlockLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public AllReader reader(LeafReaderContext context) throws IOException {
5050

5151
@Override
5252
public Builder builder(BlockFactory factory, int expectedCount) {
53-
return null;
53+
return factory.tdigestBlockBuilder(expectedCount);
5454
}
5555

5656
static class TDigestReader implements AllReader {
@@ -112,12 +112,12 @@ public Block read(BlockFactory factory, Docs docs, int offset, boolean nullsFilt
112112

113113
@Override
114114
public void read(int docId, StoredFields storedFields, Builder builder) throws IOException {
115-
ExponentialHistogramBuilder histogramBuilder = (ExponentialHistogramBuilder) builder;
115+
TDigestBuilder histogramBuilder = (TDigestBuilder) builder;
116116
minimaReader.read(docId, storedFields, histogramBuilder.minima());
117117
maximaReader.read(docId, storedFields, histogramBuilder.maxima());
118118
sumsReader.read(docId, storedFields, histogramBuilder.sums());
119119
valueCountsReader.read(docId, storedFields, histogramBuilder.valueCounts());
120-
encodedDigestReader.read(docId, storedFields, histogramBuilder.encodedHistograms());
120+
encodedDigestReader.read(docId, storedFields, histogramBuilder.encodedDigests());
121121
}
122122

123123
@Override

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/Methods.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public static String getMethod(TypeName elementType) {
317317
if (elementType.equals(Types.EXPONENTIAL_HISTOGRAM)) {
318318
return "getExponentialHistogram";
319319
}
320+
if (elementType.equals(Types.TDIGEST)) {
321+
return "getTDigestHolder";
322+
}
320323
throw new IllegalArgumentException("unknown get method for [" + elementType + "]");
321324
}
322325

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/Types.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public class Types {
137137

138138
public static final ClassName BYTES_REF = ClassName.get("org.apache.lucene.util", "BytesRef");
139139
public static final ClassName EXPONENTIAL_HISTOGRAM = ClassName.get("org.elasticsearch.exponentialhistogram", "ExponentialHistogram");
140+
public static final ClassName TDIGEST = ClassName.get("org.elasticsearch.compute.data", "TDigestHolder");
140141

141142
public static final ClassName RELEASABLE = ClassName.get("org.elasticsearch.core", "Releasable");
142143
public static final ClassName RELEASABLES = ClassName.get("org.elasticsearch.core", "Releasables");
@@ -161,7 +162,8 @@ public static TypeDef of(TypeName type, String alias, String block, String vecto
161162
TypeDef.of(TypeName.FLOAT, "FLOAT", "FloatBlock", "FloatVector", null),
162163
TypeDef.of(TypeName.DOUBLE, "DOUBLE", "DoubleBlock", "DoubleVector", null),
163164
TypeDef.of(BYTES_REF, "BYTES_REF", "BytesRefBlock", "BytesRefVector", BYTES_REF),
164-
TypeDef.of(EXPONENTIAL_HISTOGRAM, "EXPONENTIAL_HISTOGRAM", "ExponentialHistogramBlock", null, EXPONENTIAL_HISTOGRAM_SCRATCH)
165+
TypeDef.of(EXPONENTIAL_HISTOGRAM, "EXPONENTIAL_HISTOGRAM", "ExponentialHistogramBlock", null, EXPONENTIAL_HISTOGRAM_SCRATCH),
166+
TypeDef.of(TDIGEST, "TDIGEST", "TDigestBlock", null, null)
165167
)
166168
.flatMap(def -> Stream.of(def.type.toString(), def.type + "[]", def.alias).map(alias -> Map.entry(alias, def)))
167169
.collect(toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));

x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/HistogramMergeTDigestAggregatorFunction.java

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

x-pack/plugin/esql/compute/src/main/generated/org/elasticsearch/compute/aggregation/HistogramMergeTDigestAggregatorFunctionSupplier.java

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

0 commit comments

Comments
 (0)