Skip to content

Commit 820f4b7

Browse files
committed
rename Metrics to TimeSeries and add a few more test cases and comments
1 parent f150261 commit 820f4b7

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/EsqlQueryGenerator.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.KeepGenerator;
2020
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.LimitGenerator;
2121
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.LookupJoinGenerator;
22-
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.MetricsStatsGenerator;
22+
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.TimeSeriesStatsGenerator;
2323
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.MvExpandGenerator;
2424
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.RenameGenerator;
2525
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.SortGenerator;
2626
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.StatsGenerator;
2727
import org.elasticsearch.xpack.esql.qa.rest.generative.command.pipe.WhereGenerator;
2828
import org.elasticsearch.xpack.esql.qa.rest.generative.command.source.FromGenerator;
29-
import org.elasticsearch.xpack.esql.qa.rest.generative.command.source.MetricGenerator;
29+
import org.elasticsearch.xpack.esql.qa.rest.generative.command.source.TimeSeriesGenerator;
3030

3131
import java.util.List;
3232
import java.util.Set;
@@ -56,7 +56,7 @@ public record QueryExecuted(String query, int depth, List<Column> outputSchema,
5656
/**
5757
* Commands at the beginning of queries that begin queries on time series indices, eg. TS
5858
*/
59-
static List<CommandGenerator> TIME_SERIES_SOURCE_COMMANDS = List.of(MetricGenerator.INSTANCE);
59+
static List<CommandGenerator> TIME_SERIES_SOURCE_COMMANDS = List.of(TimeSeriesGenerator.INSTANCE);
6060

6161
/**
6262
* These are downstream commands, ie. that cannot appear as the first command in a query
@@ -90,7 +90,7 @@ public record QueryExecuted(String query, int depth, List<Column> outputSchema,
9090
KeepGenerator.INSTANCE,
9191
LimitGenerator.INSTANCE,
9292
LookupJoinGenerator.INSTANCE,
93-
MetricsStatsGenerator.INSTANCE,
93+
TimeSeriesStatsGenerator.INSTANCE,
9494
MvExpandGenerator.INSTANCE,
9595
RenameGenerator.INSTANCE,
9696
SortGenerator.INSTANCE,
@@ -262,10 +262,12 @@ public static String metricsAgg(List<Column> previousOutput) {
262262
if (numericPlusAggMetricFieldName == null) {
263263
yield null;
264264
}
265-
yield switch ((randomIntBetween(0, 3))) {
265+
yield switch ((randomIntBetween(0, 5))) {
266266
case 0 -> "max_over_time(" + numericPlusAggMetricFieldName + ")";
267267
case 1 -> "min_over_time(" + numericPlusAggMetricFieldName + ")";
268268
case 2 -> "sum_over_time(" + numericPlusAggMetricFieldName + ")";
269+
case 3 -> "present_over_time(" + numericPlusAggMetricFieldName + ")";
270+
case 4 -> "count_over_time(" + numericPlusAggMetricFieldName + ")";
269271
default -> "avg_over_time(" + numericPlusAggMetricFieldName + ")";
270272
};
271273
}
@@ -279,7 +281,8 @@ yield switch ((randomIntBetween(0, 3))) {
279281
}
280282
case 2 -> {
281283
// numerics except aggregate_metric_double
282-
// TODO: move to case 0 when support for aggregate_metric_double is added to these functions
284+
// TODO: add to case 0 when support for aggregate_metric_double is added to these functions
285+
// TODO: add to case 1 when support for counters is added
283286
String numericFieldName = randomNumericField(previousOutput);
284287
if (numericFieldName == null) {
285288
yield null;
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
1919
import static org.elasticsearch.xpack.esql.qa.rest.generative.EsqlQueryGenerator.randomDateField;
2020

21-
public class MetricsStatsGenerator implements CommandGenerator {
21+
public class TimeSeriesStatsGenerator implements CommandGenerator {
2222

2323
public static final String STATS = "stats";
24-
public static final CommandGenerator INSTANCE = new MetricsStatsGenerator();
24+
public static final CommandGenerator INSTANCE = new TimeSeriesStatsGenerator();
2525

2626
@Override
2727
public CommandDescription generate(
@@ -31,8 +31,9 @@ public CommandDescription generate(
3131
) {
3232
// generates stats in the form of:
3333
// `STATS some_aggregation(some_field) by optional_grouping_field, non_optional = bucket(time_field, 5minute)`
34-
// where `some_aggregation` can be a time series aggregation, or a regular aggregation
35-
// There is a variable number of aggregations per command
34+
// where `some_aggregation` can be a time series aggregation in the form of agg1(agg2_over_time(some_field)),
35+
// or a regular aggregation.
36+
// There is a variable number of aggregations per pipe
3637

3738
List<EsqlQueryGenerator.Column> nonNull = previousOutput.stream()
3839
.filter(EsqlQueryGenerator::fieldCanBeUsed)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import static org.elasticsearch.test.ESTestCase.randomIntBetween;
1717
import static org.elasticsearch.xpack.esql.qa.rest.generative.EsqlQueryGenerator.indexPattern;
1818

19-
public class MetricGenerator implements CommandGenerator {
19+
public class TimeSeriesGenerator implements CommandGenerator {
2020

21-
public static final MetricGenerator INSTANCE = new MetricGenerator();
21+
public static final TimeSeriesGenerator INSTANCE = new TimeSeriesGenerator();
2222

2323
@Override
2424
public CommandDescription generate(

0 commit comments

Comments
 (0)