Skip to content

Commit 2c205e3

Browse files
ES|QL Add primitive float variants of all aggregators to the compute engine (#109781)
This commit adds primitive float variants of all ES|QL aggregators to the compute engine. Much of the changes are mechanical and/or are generated, and retain similar type input/output params as other aggregators. Co-authored-by: Iván Cea Fontenla <[email protected]>
1 parent 1f50407 commit 2c205e3

File tree

70 files changed

+5962
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5962
-8
lines changed

docs/changelog/109781.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 109781
2+
summary: ES|QL Add primitive float variants of all aggregators to the compute engine
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

x-pack/plugin/esql/compute/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ tasks.named('stringTemplates').configure {
410410
it.inputFile = stateInputFile
411411
it.outputFile = "org/elasticsearch/compute/aggregation/LongState.java"
412412
}
413+
template {
414+
it.properties = floatProperties
415+
it.inputFile = stateInputFile
416+
it.outputFile = "org/elasticsearch/compute/aggregation/FloatState.java"
417+
}
413418
template {
414419
it.properties = doubleProperties
415420
it.inputFile = stateInputFile
@@ -463,6 +468,11 @@ tasks.named('stringTemplates').configure {
463468
it.inputFile = arrayStateInputFile
464469
it.outputFile = "org/elasticsearch/compute/aggregation/DoubleArrayState.java"
465470
}
471+
template {
472+
it.properties = floatProperties
473+
it.inputFile = arrayStateInputFile
474+
it.outputFile = "org/elasticsearch/compute/aggregation/FloatArrayState.java"
475+
}
466476
File valuesAggregatorInputFile = new File("${projectDir}/src/main/java/org/elasticsearch/compute/aggregation/X-ValuesAggregator.java.st")
467477
template {
468478
it.properties = intProperties
@@ -474,6 +484,11 @@ tasks.named('stringTemplates').configure {
474484
it.inputFile = valuesAggregatorInputFile
475485
it.outputFile = "org/elasticsearch/compute/aggregation/ValuesLongAggregator.java"
476486
}
487+
template {
488+
it.properties = floatProperties
489+
it.inputFile = valuesAggregatorInputFile
490+
it.outputFile = "org/elasticsearch/compute/aggregation/ValuesFloatAggregator.java"
491+
}
477492
template {
478493
it.properties = doubleProperties
479494
it.inputFile = valuesAggregatorInputFile
@@ -496,6 +511,11 @@ tasks.named('stringTemplates').configure {
496511
it.inputFile = rateAggregatorInputFile
497512
it.outputFile = "org/elasticsearch/compute/aggregation/RateLongAggregator.java"
498513
}
514+
template {
515+
it.properties = floatProperties
516+
it.inputFile = rateAggregatorInputFile
517+
it.outputFile = "org/elasticsearch/compute/aggregation/RateFloatAggregator.java"
518+
}
499519
template {
500520
it.properties = doubleProperties
501521
it.inputFile = rateAggregatorInputFile
@@ -514,6 +534,11 @@ tasks.named('stringTemplates').configure {
514534
it.inputFile = topListAggregatorInputFile
515535
it.outputFile = "org/elasticsearch/compute/aggregation/TopListLongAggregator.java"
516536
}
537+
template {
538+
it.properties = floatProperties
539+
it.inputFile = topListAggregatorInputFile
540+
it.outputFile = "org/elasticsearch/compute/aggregation/TopListFloatAggregator.java"
541+
}
517542
template {
518543
it.properties = doubleProperties
519544
it.inputFile = topListAggregatorInputFile
@@ -667,6 +692,11 @@ tasks.named('stringTemplates').configure {
667692
it.inputFile = bucketedSortInputFile
668693
it.outputFile = "org/elasticsearch/compute/data/sort/LongBucketedSort.java"
669694
}
695+
template {
696+
it.properties = floatProperties
697+
it.inputFile = bucketedSortInputFile
698+
it.outputFile = "org/elasticsearch/compute/data/sort/FloatBucketedSort.java"
699+
}
670700
template {
671701
it.properties = doubleProperties
672702
it.inputFile = bucketedSortInputFile

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import static org.elasticsearch.compute.gen.Types.DOUBLE_VECTOR;
4545
import static org.elasticsearch.compute.gen.Types.DRIVER_CONTEXT;
4646
import static org.elasticsearch.compute.gen.Types.ELEMENT_TYPE;
47+
import static org.elasticsearch.compute.gen.Types.FLOAT_BLOCK;
48+
import static org.elasticsearch.compute.gen.Types.FLOAT_VECTOR;
4749
import static org.elasticsearch.compute.gen.Types.INTERMEDIATE_STATE_DESC;
4850
import static org.elasticsearch.compute.gen.Types.INT_BLOCK;
4951
import static org.elasticsearch.compute.gen.Types.INT_VECTOR;
@@ -136,6 +138,8 @@ static String valueType(ExecutableElement init, ExecutableElement combine) {
136138
switch (initReturn) {
137139
case "double":
138140
return "double";
141+
case "float":
142+
return "float";
139143
case "long":
140144
return "long";
141145
case "int":
@@ -151,6 +155,7 @@ static ClassName valueBlockType(ExecutableElement init, ExecutableElement combin
151155
return switch (valueType(init, combine)) {
152156
case "boolean" -> BOOLEAN_BLOCK;
153157
case "double" -> DOUBLE_BLOCK;
158+
case "float" -> FLOAT_BLOCK;
154159
case "long" -> LONG_BLOCK;
155160
case "int" -> INT_BLOCK;
156161
case "org.apache.lucene.util.BytesRef" -> BYTES_REF_BLOCK;
@@ -162,6 +167,7 @@ static ClassName valueVectorType(ExecutableElement init, ExecutableElement combi
162167
return switch (valueType(init, combine)) {
163168
case "boolean" -> BOOLEAN_VECTOR;
164169
case "double" -> DOUBLE_VECTOR;
170+
case "float" -> FLOAT_VECTOR;
165171
case "long" -> LONG_VECTOR;
166172
case "int" -> INT_VECTOR;
167173
case "org.apache.lucene.util.BytesRef" -> BYTES_REF_VECTOR;
@@ -445,6 +451,8 @@ private String primitiveStateMethod() {
445451
return "longValue";
446452
case "org.elasticsearch.compute.aggregation.DoubleState":
447453
return "doubleValue";
454+
case "org.elasticsearch.compute.aggregation.FloatState":
455+
return "floatValue";
448456
default:
449457
throw new IllegalArgumentException(
450458
"don't know how to fetch primitive values from " + stateType + ". define combineIntermediate."
@@ -495,6 +503,9 @@ private void primitiveStateToResult(MethodSpec.Builder builder) {
495503
case "org.elasticsearch.compute.aggregation.DoubleState":
496504
builder.addStatement("blocks[offset] = driverContext.blockFactory().newConstantDoubleBlockWith(state.doubleValue(), 1)");
497505
return;
506+
case "org.elasticsearch.compute.aggregation.FloatState":
507+
builder.addStatement("blocks[offset] = driverContext.blockFactory().newConstantFloatBlockWith(state.floatValue(), 1)");
508+
return;
498509
default:
499510
throw new IllegalArgumentException("don't know how to convert state to result: " + stateType);
500511
}
@@ -521,7 +532,7 @@ private MethodSpec close() {
521532
private boolean hasPrimitiveState() {
522533
return switch (stateType.toString()) {
523534
case "org.elasticsearch.compute.aggregation.IntState", "org.elasticsearch.compute.aggregation.LongState",
524-
"org.elasticsearch.compute.aggregation.DoubleState" -> true;
535+
"org.elasticsearch.compute.aggregation.DoubleState", "org.elasticsearch.compute.aggregation.FloatState" -> true;
525536
default -> false;
526537
};
527538
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ private MethodSpec close() {
585585
private boolean hasPrimitiveState() {
586586
return switch (stateType.toString()) {
587587
case "org.elasticsearch.compute.aggregation.IntArrayState", "org.elasticsearch.compute.aggregation.LongArrayState",
588-
"org.elasticsearch.compute.aggregation.DoubleArrayState" -> true;
588+
"org.elasticsearch.compute.aggregation.DoubleArrayState", "org.elasticsearch.compute.aggregation.FloatArrayState" -> true;
589589
default -> false;
590590
};
591591
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static String vectorAccessorName(String elementTypeName) {
211211
case "INT" -> "getInt";
212212
case "LONG" -> "getLong";
213213
case "DOUBLE" -> "getDouble";
214+
case "FLOAT" -> "getFloat";
214215
case "BYTES_REF" -> "getBytesRef";
215216
default -> throw new IllegalArgumentException(
216217
"don't know how to fetch primitive values from " + elementTypeName + ". define combineIntermediate."

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ public class Types {
4141
static final ClassName INT_BLOCK = ClassName.get(DATA_PACKAGE, "IntBlock");
4242
static final ClassName LONG_BLOCK = ClassName.get(DATA_PACKAGE, "LongBlock");
4343
static final ClassName DOUBLE_BLOCK = ClassName.get(DATA_PACKAGE, "DoubleBlock");
44+
static final ClassName FLOAT_BLOCK = ClassName.get(DATA_PACKAGE, "FloatBlock");
4445

4546
static final ClassName BOOLEAN_BLOCK_BUILDER = BOOLEAN_BLOCK.nestedClass("Builder");
4647
static final ClassName BYTES_REF_BLOCK_BUILDER = BYTES_REF_BLOCK.nestedClass("Builder");
4748
static final ClassName INT_BLOCK_BUILDER = INT_BLOCK.nestedClass("Builder");
4849
static final ClassName LONG_BLOCK_BUILDER = LONG_BLOCK.nestedClass("Builder");
4950
static final ClassName DOUBLE_BLOCK_BUILDER = DOUBLE_BLOCK.nestedClass("Builder");
51+
static final ClassName FLOAT_BLOCK_BUILDER = FLOAT_BLOCK.nestedClass("Builder");
5052

5153
static final ClassName ELEMENT_TYPE = ClassName.get(DATA_PACKAGE, "ElementType");
5254

@@ -55,35 +57,41 @@ public class Types {
5557
static final ClassName INT_VECTOR = ClassName.get(DATA_PACKAGE, "IntVector");
5658
static final ClassName LONG_VECTOR = ClassName.get(DATA_PACKAGE, "LongVector");
5759
static final ClassName DOUBLE_VECTOR = ClassName.get(DATA_PACKAGE, "DoubleVector");
60+
static final ClassName FLOAT_VECTOR = ClassName.get(DATA_PACKAGE, "FloatVector");
5861

5962
static final ClassName BOOLEAN_VECTOR_BUILDER = ClassName.get(DATA_PACKAGE, "BooleanVector", "Builder");
6063
static final ClassName BYTES_REF_VECTOR_BUILDER = ClassName.get(DATA_PACKAGE, "BytesRefVector", "Builder");
6164
static final ClassName INT_VECTOR_BUILDER = ClassName.get(DATA_PACKAGE, "IntVector", "Builder");
6265
static final ClassName LONG_VECTOR_BUILDER = ClassName.get(DATA_PACKAGE, "LongVector", "Builder");
6366
static final ClassName DOUBLE_VECTOR_BUILDER = ClassName.get(DATA_PACKAGE, "DoubleVector", "Builder");
67+
static final ClassName FLOAT_VECTOR_BUILDER = ClassName.get(DATA_PACKAGE, "FloatVector", "Builder");
6468

6569
static final ClassName BOOLEAN_VECTOR_FIXED_BUILDER = ClassName.get(DATA_PACKAGE, "BooleanVector", "FixedBuilder");
6670
static final ClassName INT_VECTOR_FIXED_BUILDER = ClassName.get(DATA_PACKAGE, "IntVector", "FixedBuilder");
6771
static final ClassName LONG_VECTOR_FIXED_BUILDER = ClassName.get(DATA_PACKAGE, "LongVector", "FixedBuilder");
6872
static final ClassName DOUBLE_VECTOR_FIXED_BUILDER = ClassName.get(DATA_PACKAGE, "DoubleVector", "FixedBuilder");
73+
static final ClassName FLOAT_VECTOR_FIXED_BUILDER = ClassName.get(DATA_PACKAGE, "FloatVector", "FixedBuilder");
6974

7075
static final ClassName BOOLEAN_ARRAY_VECTOR = ClassName.get(DATA_PACKAGE, "BooleanArrayVector");
7176
static final ClassName BYTES_REF_ARRAY_VECTOR = ClassName.get(DATA_PACKAGE, "BytesRefArrayVector");
7277
static final ClassName INT_ARRAY_VECTOR = ClassName.get(DATA_PACKAGE, "IntArrayVector");
7378
static final ClassName LONG_ARRAY_VECTOR = ClassName.get(DATA_PACKAGE, "LongArrayVector");
7479
static final ClassName DOUBLE_ARRAY_VECTOR = ClassName.get(DATA_PACKAGE, "DoubleArrayVector");
80+
static final ClassName FLOAT_ARRAY_VECTOR = ClassName.get(DATA_PACKAGE, "FloatArrayVector");
7581

7682
static final ClassName BOOLEAN_ARRAY_BLOCK = ClassName.get(DATA_PACKAGE, "BooleanArrayBlock");
7783
static final ClassName BYTES_REF_ARRAY_BLOCK = ClassName.get(DATA_PACKAGE, "BytesRefArrayBlock");
7884
static final ClassName INT_ARRAY_BLOCK = ClassName.get(DATA_PACKAGE, "IntArrayBlock");
7985
static final ClassName LONG_ARRAY_BLOCK = ClassName.get(DATA_PACKAGE, "LongArrayBlock");
8086
static final ClassName DOUBLE_ARRAY_BLOCK = ClassName.get(DATA_PACKAGE, "DoubleArrayBlock");
87+
static final ClassName FLOAT_ARRAY_BLOCK = ClassName.get(DATA_PACKAGE, "FloatArrayBlock");
8188

8289
static final ClassName BOOLEAN_CONSTANT_VECTOR = ClassName.get(DATA_PACKAGE, "ConstantBooleanVector");
8390
static final ClassName BYTES_REF_CONSTANT_VECTOR = ClassName.get(DATA_PACKAGE, "ConstantBytesRefVector");
8491
static final ClassName INT_CONSTANT_VECTOR = ClassName.get(DATA_PACKAGE, "ConstantIntVector");
8592
static final ClassName LONG_CONSTANT_VECTOR = ClassName.get(DATA_PACKAGE, "ConstantLongVector");
8693
static final ClassName DOUBLE_CONSTANT_VECTOR = ClassName.get(DATA_PACKAGE, "ConstantDoubleVector");
94+
static final ClassName FLOAT_CONSTANT_VECTOR = ClassName.get(DATA_PACKAGE, "ConstantFloatVector");
8795

8896
static final ClassName AGGREGATOR_FUNCTION = ClassName.get(AGGREGATION_PACKAGE, "AggregatorFunction");
8997
static final ClassName AGGREGATOR_FUNCTION_SUPPLIER = ClassName.get(AGGREGATION_PACKAGE, "AggregatorFunctionSupplier");
@@ -162,6 +170,9 @@ static ClassName blockType(String elementType) {
162170
if (elementType.equalsIgnoreCase(TypeName.DOUBLE.toString())) {
163171
return DOUBLE_BLOCK;
164172
}
173+
if (elementType.equalsIgnoreCase(TypeName.FLOAT.toString())) {
174+
return FLOAT_BLOCK;
175+
}
165176
throw new IllegalArgumentException("unknown vector type for [" + elementType + "]");
166177
}
167178

@@ -181,6 +192,9 @@ static ClassName vectorType(TypeName elementType) {
181192
if (elementType.equals(TypeName.DOUBLE)) {
182193
return DOUBLE_VECTOR;
183194
}
195+
if (elementType.equals(TypeName.FLOAT)) {
196+
return FLOAT_VECTOR;
197+
}
184198
throw new IllegalArgumentException("unknown vector type for [" + elementType + "]");
185199
}
186200

@@ -200,6 +214,9 @@ static ClassName vectorType(String elementType) {
200214
if (elementType.equalsIgnoreCase(TypeName.DOUBLE.toString())) {
201215
return DOUBLE_VECTOR;
202216
}
217+
if (elementType.equalsIgnoreCase(TypeName.FLOAT.toString())) {
218+
return FLOAT_VECTOR;
219+
}
203220
throw new IllegalArgumentException("unknown vector type for [" + elementType + "]");
204221
}
205222

@@ -234,6 +251,12 @@ static ClassName builderType(TypeName resultType) {
234251
if (resultType.equals(DOUBLE_VECTOR)) {
235252
return DOUBLE_VECTOR_BUILDER;
236253
}
254+
if (resultType.equals(FLOAT_BLOCK)) {
255+
return FLOAT_BLOCK_BUILDER;
256+
}
257+
if (resultType.equals(FLOAT_VECTOR)) {
258+
return FLOAT_VECTOR_BUILDER;
259+
}
237260
throw new IllegalArgumentException("unknown builder type for [" + resultType + "]");
238261
}
239262

@@ -250,6 +273,9 @@ static ClassName vectorFixedBuilderType(TypeName elementType) {
250273
if (elementType.equals(TypeName.DOUBLE)) {
251274
return DOUBLE_VECTOR_FIXED_BUILDER;
252275
}
276+
if (elementType.equals(TypeName.FLOAT)) {
277+
return FLOAT_VECTOR_FIXED_BUILDER;
278+
}
253279
throw new IllegalArgumentException("unknown vector fixed builder type for [" + elementType + "]");
254280
}
255281

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

Lines changed: 120 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)