Skip to content

Commit 73f40a4

Browse files
ES|QL: Add generator for INLINE STATS (#135685)
1 parent 017ae17 commit 73f40a4

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public abstract class GenerativeRestTest extends ESRestTestCase implements Query
6666
"The incoming YAML document exceeds the limit:", // still to investigate, but it seems to be specific to the test framework
6767
"Data too large", // Circuit breaker exceptions eg. https://github.com/elastic/elasticsearch/issues/130072
6868
"optimized incorrectly due to missing references", // https://github.com/elastic/elasticsearch/issues/131509
69+
"can't build page out of released blocks", // https://github.com/elastic/elasticsearch/issues/135679
6970

7071
// Awaiting fixes for correctness
7172
"Expecting at most \\[.*\\] columns, got \\[.*\\]", // https://github.com/elastic/elasticsearch/issues/129561

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/EsqlQueryGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.xpack.esql.generator.command.pipe.EvalGenerator;
1717
import org.elasticsearch.xpack.esql.generator.command.pipe.ForkGenerator;
1818
import org.elasticsearch.xpack.esql.generator.command.pipe.GrokGenerator;
19+
import org.elasticsearch.xpack.esql.generator.command.pipe.InlineStatsGenerator;
1920
import org.elasticsearch.xpack.esql.generator.command.pipe.KeepGenerator;
2021
import org.elasticsearch.xpack.esql.generator.command.pipe.LimitGenerator;
2122
import org.elasticsearch.xpack.esql.generator.command.pipe.LookupJoinGenerator;
@@ -67,6 +68,7 @@ public class EsqlQueryGenerator {
6768
ForkGenerator.INSTANCE,
6869
GrokGenerator.INSTANCE,
6970
KeepGenerator.INSTANCE,
71+
InlineStatsGenerator.INSTANCE,
7072
LimitGenerator.INSTANCE,
7173
LookupJoinGenerator.INSTANCE,
7274
MvExpandGenerator.INSTANCE,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.generator.command.pipe;
9+
10+
import org.elasticsearch.xpack.esql.generator.Column;
11+
import org.elasticsearch.xpack.esql.generator.command.CommandGenerator;
12+
13+
import java.util.List;
14+
15+
public class InlineStatsGenerator extends StatsGenerator {
16+
public static final String INLINE_STATS = "inline stats";
17+
public static final CommandGenerator INSTANCE = new InlineStatsGenerator();
18+
19+
@Override
20+
public String commandName() {
21+
return INLINE_STATS;
22+
}
23+
24+
@Override
25+
public ValidationResult validateOutput(
26+
List<CommandDescription> previousCommands,
27+
CommandDescription commandDescription,
28+
List<Column> previousColumns,
29+
List<List<Object>> previousOutput,
30+
List<Column> columns,
31+
List<List<Object>> output
32+
) {
33+
if (commandDescription == EMPTY_DESCRIPTION) {
34+
return VALIDATION_OK;
35+
}
36+
37+
int prevCols = previousColumns.size();
38+
39+
if (previousColumns.stream().anyMatch(x -> x.name().equals("<all-fields-projected>"))) {
40+
// known bug https://github.com/elastic/elasticsearch/issues/121741
41+
prevCols--;
42+
}
43+
44+
if (prevCols > columns.size()) {
45+
return new ValidationResult(false, "Expecting at least [" + prevCols + "] columns, got [" + columns.size() + "]");
46+
}
47+
return VALIDATION_OK;
48+
}
49+
}

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/generator/command/pipe/StatsGenerator.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class StatsGenerator implements CommandGenerator {
2424
public static final String STATS = "stats";
2525
public static final CommandGenerator INSTANCE = new StatsGenerator();
2626

27+
public String commandName() {
28+
return STATS;
29+
}
30+
2731
@Override
2832
public CommandDescription generate(
2933
List<CommandDescription> previousCommands,
@@ -38,7 +42,9 @@ public CommandDescription generate(
3842
if (nonNull.isEmpty()) {
3943
return EMPTY_DESCRIPTION;
4044
}
41-
StringBuilder cmd = new StringBuilder(" | stats ");
45+
StringBuilder cmd = new StringBuilder(" | ");
46+
cmd.append(commandName());
47+
cmd.append(" ");
4248
int nStats = randomIntBetween(1, 5);
4349
for (int i = 0; i < nStats; i++) {
4450
String name;
@@ -65,7 +71,7 @@ public CommandDescription generate(
6571
cmd.append(" by " + col);
6672
}
6773
}
68-
return new CommandDescription(STATS, this, cmd.toString(), Map.of());
74+
return new CommandDescription(commandName(), this, cmd.toString(), Map.of());
6975
}
7076

7177
@Override

0 commit comments

Comments
 (0)