Skip to content

Commit 6bf5999

Browse files
authored
[ES|QL] Support for First/Last (#137408) - Code Gen & ALL_LAST (#138066)
- Minor refactoring in "build.gradle" to allow the generation of the two variants of state classes (e.g.: LongLongState and AllLongLongState) - Generate the new two state files using "All-X-2State.java.st", for all types. - Generate the new timestamp aggregator files using "All-X-ValueByTimestampAggregator.java.st", for all types. - Register ALL_LAST as snapshot function - Augment existing csv tests to exercise ALL_LAST as well, and to check for all supported types.
1 parent 0821020 commit 6bf5999

File tree

53 files changed

+8003
-120
lines changed

Some content is hidden

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

53 files changed

+8003
-120
lines changed

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

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -496,22 +496,26 @@ tasks.named('stringTemplates').configure {
496496
* Generates pairwise states. We generate the ones that we need at the moment,
497497
* but add more if you need more.
498498
*/
499-
File twoStateInputFile = file("src/main/java/org/elasticsearch/compute/aggregation/X-2State.java.st")
500-
[longProperties].forEach { v1 ->
501-
[intProperties, longProperties, floatProperties, doubleProperties, bytesRefProperties].forEach { v2 ->
502-
{
503-
var properties = [:]
504-
v1.forEach { k, v -> properties["v1_" + k] = v}
505-
v2.forEach { k, v -> properties["v2_" + k] = v}
499+
def generateTwoStateFiles = { inputFile, prefix = "" ->
500+
def v1Props = [longProperties]
501+
def v2Props = [intProperties, longProperties, floatProperties, doubleProperties, bytesRefProperties]
502+
v1Props.forEach { v1 ->
503+
v2Props.forEach { v2 ->
504+
def properties = [:]
505+
v1.forEach { k, v -> properties["v1_" + k] = v }
506+
v2.forEach { k, v -> properties["v2_" + k] = v }
506507
template {
507508
it.properties = properties
508-
it.inputFile = twoStateInputFile
509-
it.outputFile = "org/elasticsearch/compute/aggregation/${v1.Type}${v2.Type}State.java"
509+
it.inputFile = inputFile
510+
it.outputFile = "org/elasticsearch/compute/aggregation/${prefix}${v1.Type}${v2.Type}State.java"
510511
}
511512
}
512513
}
513514
}
514515

516+
generateTwoStateFiles(file("src/main/java/org/elasticsearch/compute/aggregation/X-2State.java.st"))
517+
generateTwoStateFiles(file("src/main/java/org/elasticsearch/compute/aggregation/X-All2State.java.st"), "All")
518+
515519
File irateAggregatorInputFile = file("src/main/java/org/elasticsearch/compute/aggregation/X-IrateAggregator.java.st")
516520
template {
517521
it.properties = intProperties
@@ -958,37 +962,42 @@ tasks.named('stringTemplates').configure {
958962
}
959963

960964
// TODO: add {value}_over_time for other types: boolean, bytes_refs
961-
File valueByTimestampAggregatorInputFile = file("src/main/java/org/elasticsearch/compute/aggregation/X-ValueByTimestampAggregator.java.st")
962-
["First", "Last"].forEach { Occurrence ->
963-
{
964-
template {
965-
it.properties = addOccurrence(intProperties, Occurrence)
966-
it.inputFile = valueByTimestampAggregatorInputFile
967-
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}IntByTimestampAggregator.java"
968-
}
969-
template {
970-
it.properties = addOccurrence(longProperties, Occurrence)
971-
it.inputFile = valueByTimestampAggregatorInputFile
972-
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}LongByTimestampAggregator.java"
973-
}
974-
template {
975-
it.properties = addOccurrence(floatProperties, Occurrence)
976-
it.inputFile = valueByTimestampAggregatorInputFile
977-
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}FloatByTimestampAggregator.java"
978-
}
979-
template {
980-
it.properties = addOccurrence(doubleProperties, Occurrence)
981-
it.inputFile = valueByTimestampAggregatorInputFile
982-
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}DoubleByTimestampAggregator.java"
983-
}
984-
template {
985-
it.properties = addOccurrence(bytesRefProperties, Occurrence)
986-
it.inputFile = valueByTimestampAggregatorInputFile
987-
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}BytesRefByTimestampAggregator.java"
965+
def generateTimestampAggregatorClasses = { inputFilename, prefix = "" ->
966+
def inputFile = file(inputFilename)
967+
["First", "Last"].forEach { Occurrence ->
968+
{
969+
template {
970+
it.properties = addOccurrence(intProperties, Occurrence) + [Prefix: prefix]
971+
it.inputFile = inputFile
972+
it.outputFile = "org/elasticsearch/compute/aggregation/${prefix}${Occurrence}IntByTimestampAggregator.java"
973+
}
974+
template {
975+
it.properties = addOccurrence(longProperties, Occurrence) + [Prefix: prefix]
976+
it.inputFile = inputFile
977+
it.outputFile = "org/elasticsearch/compute/aggregation/${prefix}${Occurrence}LongByTimestampAggregator.java"
978+
}
979+
template {
980+
it.properties = addOccurrence(floatProperties, Occurrence) + [Prefix: prefix]
981+
it.inputFile = inputFile
982+
it.outputFile = "org/elasticsearch/compute/aggregation/${prefix}${Occurrence}FloatByTimestampAggregator.java"
983+
}
984+
template {
985+
it.properties = addOccurrence(doubleProperties, Occurrence) + [Prefix: prefix]
986+
it.inputFile = inputFile
987+
it.outputFile = "org/elasticsearch/compute/aggregation/${prefix}${Occurrence}DoubleByTimestampAggregator.java"
988+
}
989+
template {
990+
it.properties = addOccurrence(bytesRefProperties, Occurrence) + [Prefix: prefix]
991+
it.inputFile = inputFile
992+
it.outputFile = "org/elasticsearch/compute/aggregation/${prefix}${Occurrence}BytesRefByTimestampAggregator.java"
993+
}
988994
}
989995
}
990996
}
991997

998+
generateTimestampAggregatorClasses("src/main/java/org/elasticsearch/compute/aggregation/X-ValueByTimestampAggregator.java.st", "")
999+
generateTimestampAggregatorClasses("src/main/java/org/elasticsearch/compute/aggregation/X-AllValueByTimestampAggregator.java.st", "All")
1000+
9921001
File rateAggregatorInputFile = file("src/main/java/org/elasticsearch/compute/aggregation/X-RateGroupingAggregatorFunction.java.st")
9931002
template {
9941003
it.properties = intProperties

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.elasticsearch.compute.gen.Types.DOUBLE_BLOCK;
2222
import static org.elasticsearch.compute.gen.Types.EXPRESSION_EVALUATOR;
2323
import static org.elasticsearch.compute.gen.Types.EXPRESSION_EVALUATOR_FACTORY;
24+
import static org.elasticsearch.compute.gen.Types.FLOAT_BLOCK;
2425
import static org.elasticsearch.compute.gen.Types.INT_BLOCK;
2526
import static org.elasticsearch.compute.gen.Types.LONG_BLOCK;
2627
import static org.elasticsearch.compute.gen.Types.blockType;
@@ -120,6 +121,7 @@ static boolean isBlockType(TypeName type) {
120121
return type.equals(INT_BLOCK)
121122
|| type.equals(LONG_BLOCK)
122123
|| type.equals(DOUBLE_BLOCK)
124+
|| type.equals(FLOAT_BLOCK)
123125
|| type.equals(BOOLEAN_BLOCK)
124126
|| type.equals(BYTES_REF_BLOCK);
125127
}

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

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