Skip to content

Commit 0614371

Browse files
committed
Add doc for agg_over_time
1 parent f07de5a commit 0614371

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/k8s-timeseries.csv-spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ null | three | 2024-05-10T00:01:00.000
167167

168168

169169
max_over_time
170+
170171
required_capability: metrics_command
171172
required_capability: max_over_time
172-
TS k8s | STATS cost=sum(max_over_time(network.cost)) BY cluster, time_bucket = bucket(@timestamp,1minute) | SORT cost DESC, time_bucket DESC, cluster | LIMIT 10;
173+
// tag::max_over_time[]
174+
TS k8s | STATS cost=sum(max_over_time(network.cost)) BY cluster, time_bucket = bucket(@timestamp,1minute)
175+
// tag::max_over_time[]
176+
| SORT cost DESC, time_bucket DESC, cluster | LIMIT 10;
173177

174178
cost:double | cluster:keyword | time_bucket:datetime
175179
32.75 | qa | 2024-05-10T00:17:00.000Z

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public enum FunctionType {
2121
* For example, {@code MAX} in {@code | STATS MAX(LENGTH(string))}.
2222
*/
2323
AGGREGATE,
24+
25+
/**
26+
* Functions that can only appear in the aggregate" position of a {@code STATS}
27+
* started with TS.
28+
* For example, {@code MAX_OVER_TIME} in {@code | STATS MAX(MAX_OVER_TIME(string))}.
29+
*/
30+
TIME_SERIES_AGGREGATE,
2431
/**
2532
* Functions that can only appear in the "grouping" position of a {@code STATS}.
2633
* For example, {@code CATEGORIZE} in {@code | STATS MAX(a) BY CATEGORIZE(message)}.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1515
import org.elasticsearch.xpack.esql.core.tree.Source;
1616
import org.elasticsearch.xpack.esql.core.type.DataType;
17+
import org.elasticsearch.xpack.esql.expression.function.Example;
1718
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
1819
import org.elasticsearch.xpack.esql.expression.function.FunctionType;
1920
import org.elasticsearch.xpack.esql.expression.function.Param;
@@ -36,7 +37,8 @@ public class MaxOverTime extends TimeSeriesAggregateFunction {
3637
@FunctionInfo(
3738
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "long", "version" },
3839
description = "The maximum over time value of a field.",
39-
type = FunctionType.AGGREGATE
40+
type = FunctionType.TIME_SERIES_AGGREGATE,
41+
examples = { @Example(file = "k8s-timeseries", tag = "max_over_time") }
4042
)
4143
public MaxOverTime(
4244
Source source,

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ void renderKibanaFunctionDefinition(
10581058
builder.field("type", switch (info.type()) {
10591059
case SCALAR -> "scalar";
10601060
case AGGREGATE -> "agg";
1061+
case TIME_SERIES_AGGREGATE -> "time_series_agg";
10611062
case GROUPING -> "grouping";
10621063
});
10631064
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function;
9+
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
import org.elasticsearch.xpack.esql.expression.function.aggregate.Max;
13+
import org.elasticsearch.xpack.esql.expression.function.aggregate.MaxOverTime;
14+
import org.elasticsearch.xpack.esql.expression.function.aggregate.MaxTests;
15+
16+
import java.util.List;
17+
import java.util.function.Supplier;
18+
19+
import static org.hamcrest.Matchers.equalTo;
20+
21+
public class MaxOverTimeTests extends MaxTests {
22+
public MaxOverTimeTests(Supplier<TestCaseSupplier.TestCase> testCaseSupplier) {
23+
super(testCaseSupplier);
24+
}
25+
26+
@Override
27+
protected Expression build(Source source, List<Expression> args) {
28+
MaxOverTime maxOverTime = new MaxOverTime(source, args.get(0));
29+
Max perTimeSeriesAggregation = maxOverTime.perTimeSeriesAggregation();
30+
assertThat(super.build(source, args), equalTo(perTimeSeriesAggregation));
31+
return perTimeSeriesAggregation;
32+
}
33+
}

0 commit comments

Comments
 (0)