Skip to content

Commit d07e732

Browse files
committed
fixup
1 parent 0fd0bb9 commit d07e732

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,6 @@ public boolean equals(Object obj) {
119119
@Override
120120
public void postAnalysisVerification(Failures failures) {
121121
super.postAnalysisVerification(failures);
122-
// We forbid aggregating 'dimension' fields - these are only allowed inside grouping functions
123-
aggregates().forEach(agg -> agg.forEachDown(e -> {
124-
if (e instanceof FieldAttribute fieldAttr && fieldAttr.isDimension()) {
125-
failures.add(
126-
fail(
127-
fieldAttr,
128-
"cannot aggregate dimension field [{}] in a time-series aggregation. "
129-
+ "If you want to aggregate a dimension field, use the FROM "
130-
+ "command instead of the TS command.",
131-
fieldAttr.sourceText()
132-
)
133-
);
134-
}
135-
}));
136122
// We forbid grouping by a metric field itself. Metric fields are allowed only inside aggregate functions.
137123
groupings().forEach(g -> g.forEachDown(e -> {
138124
if (e instanceof FieldAttribute fieldAttr && fieldAttr.isMetric()) {
@@ -217,6 +203,18 @@ protected void checkTimeSeriesAggregates(Failures failures) {
217203
fail(count, "count_star [{}] can't be used with TS command; use count on a field instead", outer.sourceText())
218204
);
219205
}
206+
if (outer.field() instanceof FieldAttribute fa && fa.isDimension()) {
207+
failures.add(
208+
fail(
209+
this,
210+
"cannot use dimension field [{}] in a time-series aggregation function [{}]. "
211+
+ "Dimension fields can only be used for grouping in a BY clause. To aggregate "
212+
+ "dimension fields, use the FROM command instead of the TS command.",
213+
fa.sourceText(),
214+
outer.sourceText()
215+
)
216+
);
217+
}
220218
if (outer instanceof TimeSeriesAggregateFunction ts) {
221219
outer.field()
222220
.forEachDown(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,8 +2693,9 @@ public void testNoDimensionsInAggsOnlyInByClause() {
26932693
assertThat(
26942694
error("TS test | STATS count(host) BY bucket(@timestamp, 1 minute)", tsdb),
26952695
equalTo(
2696-
"1:23: cannot aggregate dimension field [host] in a time-series aggregation. "
2697-
+ "If you want to aggregate a dimension field, use the FROM command instead of the TS command."
2696+
"1:11: cannot use dimension field [host] in a time-series aggregation function [count(host)]. "
2697+
+ "Dimension fields can only be used for grouping in a BY clause. "
2698+
+ "To aggregate dimension fields, use the FROM command instead of the TS command."
26982699
)
26992700
);
27002701
}

0 commit comments

Comments
 (0)