Skip to content

Commit 5467344

Browse files
authored
[ES|QL] Don't allow MV_EXPAND prior to STATS with TS (#136931)
Resolves #136928
1 parent 2e340de commit 5467344

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/changelog/136931.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 136931
2+
summary: Don't allow MV_EXPAND prior to STATS with TS
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 136928

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/TimeSeriesAggregate.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ public void postAnalysisVerification(Failures failures) {
193193
)
194194
);
195195
}
196+
// reject `TS metrics | MV_EXPAND ... | STATS ...`
197+
if (p instanceof MvExpand mvExpand) {
198+
failures.add(
199+
fail(
200+
mvExpand,
201+
"mv_expand [{}] in the time-series before the first aggregation [{}] is not allowed",
202+
mvExpand.sourceText(),
203+
this.sourceText()
204+
)
205+
);
206+
}
196207
});
197208
}
198209

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,18 @@ STATS max(max_over_time(network.connections)) BY host, time_bucket = bucket(@tim
28132813
can only be used after STATS when used with TS command"""));
28142814
}
28152815

2816+
public void testMvExpandBeforeTSStatsNotAllowed() {
2817+
assertThat(error("TS test | MV_EXPAND name | STATS max(network.connections)", tsdb), equalTo("""
2818+
1:11: mv_expand [MV_EXPAND name] in the time-series before the first aggregation \
2819+
[STATS max(network.connections)] is not allowed"""));
2820+
2821+
assertThat(error("TS test | MV_EXPAND name | MV_EXPAND network.connections | STATS max(network.connections)", tsdb), equalTo("""
2822+
1:28: mv_expand [MV_EXPAND network.connections] in the time-series before the first aggregation \
2823+
[STATS max(network.connections)] is not allowed
2824+
line 1:11: mv_expand [MV_EXPAND name] in the time-series before the first aggregation \
2825+
[STATS max(network.connections)] is not allowed"""));
2826+
}
2827+
28162828
private void checkVectorFunctionsNullArgs(String functionInvocation) throws Exception {
28172829
query("from test | eval similarity = " + functionInvocation, fullTextAnalyzer);
28182830
}

0 commit comments

Comments
 (0)