Skip to content

Commit 2f991b1

Browse files
committed
tests to demonstrate the bug
1 parent 19fc7ff commit 2f991b1

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,22 @@ cnt:long | cluster:keyword | pod:keyword
559559
1 | prod | two
560560
1 | prod | three
561561
;
562+
563+
Max of Rate with Bucket
564+
TS k8s
565+
| STATS maxRate = max(rate(network.total_cost)) BY tbucket = bucket(@timestamp, 1hour)
566+
;
567+
568+
maxRate:double | tbucket:datetime
569+
0.058979885057471274 | 2024-05-10T00:00:00.000Z
570+
;
571+
572+
Max of Rate with Bucket, Rename Timestamp
573+
TS k8s
574+
| RENAME `@timestamp` AS newTs
575+
| STATS maxRate = max(rate(network.total_cost)) BY tbucket = bucket(newTs, 1hour)
576+
;
577+
578+
maxRate:double | tbucket:datetime
579+
0.058979885057471274 | 2024-05-10T00:00:00.000Z
580+
;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.analysis;
9+
10+
import org.elasticsearch.index.IndexMode;
11+
import org.elasticsearch.xpack.esql.plan.logical.EsRelation;
12+
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
13+
import org.elasticsearch.xpack.esql.rule.Rule;
14+
15+
public class AddTimeSeriesFields extends Rule<LogicalPlan, LogicalPlan> {
16+
@Override
17+
public LogicalPlan apply(LogicalPlan logicalPlan) {
18+
/*
19+
return logicalPlan.transformUp(p -> p instanceof EsRelation r && r.indexMode()== IndexMode.TIME_SERIES, relation -> {
20+
21+
});
22+
23+
*/
24+
return logicalPlan;
25+
}
26+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/TranslateTimeSeriesAggregateTests.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected LogicalPlan planK8s(String query) {
7979
* }</pre>
8080
*/
8181
public void testMaxOverTime() {
82-
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
82+
assumeTrue("requires metrics command", EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled());
8383
LogicalPlan plan = planK8s("""
8484
TS k8s
8585
| STATS count(max_over_time(network.cost)) BY time_bucket = BUCKET(@timestamp, 1 minute)
@@ -94,7 +94,7 @@ public void testMaxOverTime() {
9494
}
9595

9696
public void testMaxOfRate() {
97-
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
97+
assumeTrue("requires metrics command", EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled());
9898
LogicalPlan plan = planK8s("""
9999
TS k8s
100100
| STATS max(rate(network.total_bytes_in)) BY time_bucket = BUCKET(@timestamp, 1 minute)
@@ -126,7 +126,7 @@ public void testMaxOfRate() {
126126
* }</pre>
127127
*/
128128
public void testAvgOfAvgOverTime() {
129-
assumeTrue("requires metrics command", EsqlCapabilities.Cap.METRICS_COMMAND.isEnabled());
129+
assumeTrue("requires metrics command", EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled());
130130
LogicalPlan plan = planK8s("""
131131
TS k8s
132132
| STATS avg_cost=avg(avg_over_time(network.cost)) BY cluster, time_bucket = bucket(@timestamp,1minute)
@@ -142,4 +142,31 @@ public void testAvgOfAvgOverTime() {
142142
Eval bucketEval = as(innerStats.child(), Eval.class); // compute the tbucket
143143
EsRelation relation = as(bucketEval.child(), EsRelation.class);
144144
}
145+
146+
public void testRenameTimestampWithRate() {
147+
assumeTrue("requires metrics command", EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled());
148+
LogicalPlan plan = planK8s("""
149+
TS k8s
150+
| RENAME `@timestamp` AS newTs
151+
| STATS maxRate = max(rate(network.total_cost)) BY tbucket = bucket(newTs, 1hour)
152+
""");
153+
}
154+
155+
public void testRenameTimestampWithOverTimeFunction() {
156+
assumeTrue("requires metrics command", EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled());
157+
LogicalPlan plan = planK8s("""
158+
TS k8s
159+
| RENAME `@timestamp` AS newTs
160+
| STATS maxRate = max(max_over_time(network.eth0.tx)) BY tbucket = bucket(newTs, 1hour)
161+
""");
162+
}
163+
164+
public void testRenameTimestampWithOverTimeFunctionWithTbucket() {
165+
assumeTrue("requires metrics command", EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled());
166+
LogicalPlan plan = planK8s("""
167+
TS k8s
168+
| RENAME `@timestamp` AS newTs
169+
| STATS maxRate = max(max_over_time(network.eth0.tx)) BY tbucket = tbucket(1hour)
170+
""");
171+
}
145172
}

0 commit comments

Comments
 (0)