Skip to content

Commit ebe72a2

Browse files
committed
Add tests and docs for first/last over time
1 parent 87ec950 commit ebe72a2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/FirstOverTime.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.List;
3535

3636
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
37+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
3738
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
3839

3940
public class FirstOverTime extends TimeSeriesAggregateFunction implements OptionalArgument, ToAggregator {
@@ -57,7 +58,7 @@ public FirstOverTime(Source source, @Param(name = "field", type = { "long", "int
5758
this(source, field, new UnresolvedAttribute(source, "@timestamp"));
5859
}
5960

60-
FirstOverTime(Source source, Expression field, Expression timestamp) {
61+
public FirstOverTime(Source source, Expression field, Expression timestamp) {
6162
this(source, field, Literal.TRUE, timestamp);
6263
}
6364

@@ -111,7 +112,16 @@ public DataType dataType() {
111112

112113
@Override
113114
protected TypeResolution resolveType() {
114-
return isType(field(), dt -> dt.isNumeric() && dt != DataType.UNSIGNED_LONG, sourceText(), DEFAULT, "numeric except unsigned_long");
115+
return isType(field(), dt -> dt.isNumeric() && dt != DataType.UNSIGNED_LONG, sourceText(), DEFAULT, "numeric except unsigned_long")
116+
.and(
117+
isType(
118+
timestamp,
119+
dt -> dt == DataType.DATETIME || dt == DataType.DATE_NANOS,
120+
sourceText(),
121+
SECOND,
122+
"date_nanos or datetime"
123+
)
124+
);
115125
}
116126

117127
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/LastOverTime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class LastOverTime extends TimeSeriesAggregateFunction implements Optiona
5454
note = "Available with the [TS](/reference/query-languages/esql/commands/source-commands.md#esql-ts) command in snapshot builds",
5555
examples = { @Example(file = "k8s-timeseries", tag = "last_over_time") }
5656
)
57-
LastOverTime(Source source, @Param(name = "field", type = { "long", "integer", "double" }) Expression field) {
57+
public LastOverTime(Source source, @Param(name = "field", type = { "long", "integer", "double" }) Expression field) {
5858
this(source, field, new UnresolvedAttribute(source, "@timestamp"));
5959
}
6060

0 commit comments

Comments
 (0)