Skip to content

Commit 7f3f934

Browse files
committed
response to PR feedback
1 parent 484b171 commit 7f3f934

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/IgnoreNullMetrics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.xpack.esql.plan.logical.EsRelation;
1818
import org.elasticsearch.xpack.esql.plan.logical.Filter;
1919
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
20+
import org.elasticsearch.xpack.esql.plan.logical.TimeSeriesAggregate;
2021
import org.elasticsearch.xpack.esql.plan.logical.UnresolvedRelation;
2122
import org.elasticsearch.xpack.esql.rule.Rule;
2223

@@ -58,7 +59,7 @@ public LogicalPlan apply(LogicalPlan logicalPlan) {
5859
private Set<Attribute> collectMetrics(LogicalPlan logicalPlan) {
5960
Set<Attribute> metrics = new HashSet<>();
6061
logicalPlan.forEachDown(p -> {
61-
if (p instanceof Aggregate) {
62+
if (p instanceof TimeSeriesAggregate) {
6263
p.forEachExpression(Attribute.class, attr -> {
6364
if (attr.isMetric()) {
6465
metrics.add(attr);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/IgnoreNullMetricsTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,25 @@ public void testSkipCoalescedMetrics() {
182182
FieldAttribute attribute = as(condition.field(), FieldAttribute.class);
183183
assertEquals("metric_1", attribute.fieldName().string());
184184
}
185+
186+
/**
187+
* check that stats blocks after the first are not sourced for adding metrics to the filter
188+
*/
189+
public void testMultipleStats() {
190+
LogicalPlan actual = analyze("""
191+
TS test
192+
| STATS m = max(max_over_time(metric_1))
193+
| STATS sum(m)
194+
| LIMIT 10
195+
""");
196+
Limit limit = as(actual, Limit.class);
197+
Aggregate sumAgg = as(limit.child(), Aggregate.class);
198+
Aggregate outerAgg = as(sumAgg.child(), Aggregate.class);
199+
Aggregate tsAgg = as(outerAgg.child(), Aggregate.class);
200+
Filter filter = as(tsAgg.child(), Filter.class);
201+
IsNotNull condition = as(filter.condition(), IsNotNull.class);
202+
FieldAttribute attribute = as(condition.field(), FieldAttribute.class);
203+
assertEquals("metric_1", attribute.fieldName().string());
204+
205+
}
185206
}

0 commit comments

Comments
 (0)