Skip to content

Commit d4bddc9

Browse files
authored
Add first_over_time (#127656)
This change adds support for first_over_time for time-series data streams, similar to last_over_time.
1 parent 4985a61 commit d4bddc9

25 files changed

+1926
-42
lines changed

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def prop(Name, Type, type, Wrapper, TYPE, BYTES, Array, Hash) {
7979
]
8080
}
8181

82+
def addOccurrence(props, Occurrence) {
83+
def newProps = props.collectEntries { [(it.key): it.value] }
84+
newProps["Occurrence"] = Occurrence
85+
newProps["First"] = Occurrence == "First" ? "true" : ""
86+
newProps["Last"] = Occurrence == "Last" ? "true" : ""
87+
return newProps
88+
}
89+
8290
tasks.named('stringTemplates').configure {
8391
var intProperties = prop("Int", "Int", "int", "Integer", "INT", "Integer.BYTES", "IntArray", "LongHash")
8492
var floatProperties = prop("Float", "Float", "float", "Float", "FLOAT", "Float.BYTES", "FloatArray", "LongHash")
@@ -862,27 +870,30 @@ tasks.named('stringTemplates').configure {
862870
it.outputFile = "org/elasticsearch/xpack/compute/operator/lookup/EnrichResultBuilderForBoolean.java"
863871
}
864872

865-
// TODO: add last_over_time for other types: boolean, bytes_refs
866-
File lastOverTimeAggregatorInputFile = file("src/main/java/org/elasticsearch/compute/aggregation/X-LastOverTimeAggregator.java.st")
867-
template {
868-
it.properties = intProperties
869-
it.inputFile = lastOverTimeAggregatorInputFile
870-
it.outputFile = "org/elasticsearch/compute/aggregation/LastOverTimeIntAggregator.java"
871-
}
872-
template {
873-
it.properties = longProperties
874-
it.inputFile = lastOverTimeAggregatorInputFile
875-
it.outputFile = "org/elasticsearch/compute/aggregation/LastOverTimeLongAggregator.java"
873+
// TODO: add {value}_over_time for other types: boolean, bytes_refs
874+
File valueOverTimeAggregatorInputFile = file("src/main/java/org/elasticsearch/compute/aggregation/X-ValueOverTimeAggregator.java.st")
875+
["First", "Last"].forEach { Occurrence ->
876+
{
877+
template {
878+
it.properties = addOccurrence(intProperties, Occurrence)
879+
it.inputFile = valueOverTimeAggregatorInputFile
880+
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}OverTimeIntAggregator.java"
881+
}
882+
template {
883+
it.properties = addOccurrence(longProperties, Occurrence)
884+
it.inputFile = valueOverTimeAggregatorInputFile
885+
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}OverTimeLongAggregator.java"
886+
}
887+
template {
888+
it.properties = addOccurrence(floatProperties, Occurrence)
889+
it.inputFile = valueOverTimeAggregatorInputFile
890+
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}OverTimeFloatAggregator.java"
891+
}
892+
template {
893+
it.properties = addOccurrence(doubleProperties, Occurrence)
894+
it.inputFile = valueOverTimeAggregatorInputFile
895+
it.outputFile = "org/elasticsearch/compute/aggregation/${Occurrence}OverTimeDoubleAggregator.java"
896+
}
897+
}
876898
}
877-
template {
878-
it.properties = floatProperties
879-
it.inputFile = lastOverTimeAggregatorInputFile
880-
it.outputFile = "org/elasticsearch/compute/aggregation/LastOverTimeFloatAggregator.java"
881-
}
882-
template {
883-
it.properties = doubleProperties
884-
it.inputFile = lastOverTimeAggregatorInputFile
885-
it.outputFile = "org/elasticsearch/compute/aggregation/LastOverTimeDoubleAggregator.java"
886-
}
887-
888899
}

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

Lines changed: 151 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-src/org/elasticsearch/compute/aggregation/FirstOverTimeFloatAggregator.java

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