Skip to content

Commit 9661efe

Browse files
committed
Improved replacement rule assertion
1 parent 375e83d commit 9661efe

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
import org.elasticsearch.xpack.esql.rule.Rule;
1616

1717
/**
18-
* Looks for the structure:
18+
* Looks for:
1919
* <pre>
2020
* {@link TopN}
2121
* \_{@link Aggregate}
2222
* </pre>
23-
* And replaces it with {@link TopNAggregate}.
23+
* And replaces it with a {@link TopNAggregate}.
24+
* <p>
25+
* {@link TimeSeriesAggregate} subclass should not appear here after a {@link TopN}. See {@link TranslateTimeSeriesAggregate}.
26+
* </p>
2427
*/
2528
public class ReplaceTopNAndAggregateWithTopNAggregate extends Rule<TopN, LogicalPlan> {
2629

@@ -31,8 +34,7 @@ public LogicalPlan apply(LogicalPlan plan) {
3134

3235
private LogicalPlan applyRule(TopN topN) {
3336
if (topN.child() instanceof Aggregate aggregate && aggregate instanceof TopNAggregate == false) {
34-
// TimeSeriesAggregate shouldn't appear after a TopN when this rule is executed
35-
assert aggregate instanceof TimeSeriesAggregate == false : "TimeSeriesAggregate should not be replaced with TopNAggregate";
37+
assert aggregate.getClass() == Aggregate.class : "Only Aggregate can be replaced with TopNAggregate";
3638

3739
return new TopNAggregate(
3840
aggregate.source(),

0 commit comments

Comments
 (0)