From 1097d7ccbb668f9c8a12909fcc26f4a905fd4c5c Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Tue, 30 Sep 2025 11:34:23 +0200 Subject: [PATCH 1/3] ES|QL: Add generator for INLINE STATS --- .../rest/generative/GenerativeRestTest.java | 1 + .../esql/generator/EsqlQueryGenerator.java | 2 + .../command/pipe/InlineStatsGenerator.java | 50 +++++++++++++++++++ .../command/pipe/StatsGenerator.java | 10 +++- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/InlineStatsGenerator.java 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 c1634bf9885fb..50cedec3eb749 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 c6b6d7ee9b1b3..e7398ebc13282 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; @@ -68,6 +69,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..75c41e6b20e27 --- /dev/null +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/InlineStatsGenerator.java @@ -0,0 +1,50 @@ +/* + * 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; + } + + // the -1 is for the additional RENAME, that could drop one column + int prevCols = previousColumns.size() - 1; + + 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 From 1c3d7c606c73f7266c5c145e78efc6a4a027f829 Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Tue, 30 Sep 2025 13:21:47 +0200 Subject: [PATCH 2/3] Leftover --- .../esql/generator/command/pipe/InlineStatsGenerator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 index 75c41e6b20e27..346e025383839 100644 --- 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 @@ -33,9 +33,8 @@ public ValidationResult validateOutput( if (commandDescription == EMPTY_DESCRIPTION) { return VALIDATION_OK; } - - // the -1 is for the additional RENAME, that could drop one column - int prevCols = previousColumns.size() - 1; + + int prevCols = previousColumns.size(); if (previousColumns.stream().anyMatch(x -> x.name().equals(""))) { // known bug https://github.com/elastic/elasticsearch/issues/121741 From f248f2895cc7e74b54761b9ae3a79a67ec119ad5 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Tue, 30 Sep 2025 11:29:46 +0000 Subject: [PATCH 3/3] [CI] Auto commit changes from spotless --- .../xpack/esql/generator/command/pipe/InlineStatsGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 346e025383839..973f459777ecf 100644 --- 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 @@ -33,7 +33,7 @@ public ValidationResult validateOutput( if (commandDescription == EMPTY_DESCRIPTION) { return VALIDATION_OK; } - + int prevCols = previousColumns.size(); if (previousColumns.stream().anyMatch(x -> x.name().equals(""))) {