diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java index bd9f9add8ea09..ee1fe6d3b2c1d 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java @@ -66,6 +66,7 @@ public abstract class GenerativeRestTest extends ESRestTestCase implements Query "The incoming YAML document exceeds the limit:", // still to investigate, but it seems to be specific to the test framework "Data too large", // Circuit breaker exceptions eg. https://github.com/elastic/elasticsearch/issues/130072 "optimized incorrectly due to missing references", // https://github.com/elastic/elasticsearch/issues/131509 + "can't build page out of released blocks", // https://github.com/elastic/elasticsearch/issues/135679 // Awaiting fixes for correctness "Expecting at most \\[.*\\] columns, got \\[.*\\]", // https://github.com/elastic/elasticsearch/issues/129561 diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/EsqlQueryGenerator.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/EsqlQueryGenerator.java index 47e47fa4de1ab..cdb262c91dfdb 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/EsqlQueryGenerator.java +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/EsqlQueryGenerator.java @@ -16,6 +16,7 @@ import org.elasticsearch.xpack.esql.generator.command.pipe.EvalGenerator; import org.elasticsearch.xpack.esql.generator.command.pipe.ForkGenerator; import org.elasticsearch.xpack.esql.generator.command.pipe.GrokGenerator; +import org.elasticsearch.xpack.esql.generator.command.pipe.InlineStatsGenerator; import org.elasticsearch.xpack.esql.generator.command.pipe.KeepGenerator; import org.elasticsearch.xpack.esql.generator.command.pipe.LimitGenerator; import org.elasticsearch.xpack.esql.generator.command.pipe.LookupJoinGenerator; @@ -67,6 +68,7 @@ public class EsqlQueryGenerator { ForkGenerator.INSTANCE, GrokGenerator.INSTANCE, KeepGenerator.INSTANCE, + InlineStatsGenerator.INSTANCE, LimitGenerator.INSTANCE, LookupJoinGenerator.INSTANCE, MvExpandGenerator.INSTANCE, diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/InlineStatsGenerator.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/InlineStatsGenerator.java new file mode 100644 index 0000000000000..973f459777ecf --- /dev/null +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/InlineStatsGenerator.java @@ -0,0 +1,49 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.esql.generator.command.pipe; + +import org.elasticsearch.xpack.esql.generator.Column; +import org.elasticsearch.xpack.esql.generator.command.CommandGenerator; + +import java.util.List; + +public class InlineStatsGenerator extends StatsGenerator { + public static final String INLINE_STATS = "inline stats"; + public static final CommandGenerator INSTANCE = new InlineStatsGenerator(); + + @Override + public String commandName() { + return INLINE_STATS; + } + + @Override + public ValidationResult validateOutput( + List previousCommands, + CommandDescription commandDescription, + List previousColumns, + List> previousOutput, + List columns, + List> output + ) { + if (commandDescription == EMPTY_DESCRIPTION) { + return VALIDATION_OK; + } + + int prevCols = previousColumns.size(); + + if (previousColumns.stream().anyMatch(x -> x.name().equals(""))) { + // known bug https://github.com/elastic/elasticsearch/issues/121741 + prevCols--; + } + + if (prevCols > columns.size()) { + return new ValidationResult(false, "Expecting at least [" + prevCols + "] columns, got [" + columns.size() + "]"); + } + return VALIDATION_OK; + } +} diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/StatsGenerator.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/StatsGenerator.java index 30464c28a8464..19d53068e39ac 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/StatsGenerator.java +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/StatsGenerator.java @@ -24,6 +24,10 @@ public class StatsGenerator implements CommandGenerator { public static final String STATS = "stats"; public static final CommandGenerator INSTANCE = new StatsGenerator(); + public String commandName() { + return STATS; + } + @Override public CommandDescription generate( List previousCommands, @@ -38,7 +42,9 @@ public CommandDescription generate( if (nonNull.isEmpty()) { return EMPTY_DESCRIPTION; } - StringBuilder cmd = new StringBuilder(" | stats "); + StringBuilder cmd = new StringBuilder(" | "); + cmd.append(commandName()); + cmd.append(" "); int nStats = randomIntBetween(1, 5); for (int i = 0; i < nStats; i++) { String name; @@ -65,7 +71,7 @@ public CommandDescription generate( cmd.append(" by " + col); } } - return new CommandDescription(STATS, this, cmd.toString(), Map.of()); + return new CommandDescription(commandName(), this, cmd.toString(), Map.of()); } @Override