Skip to content

Commit 54aec22

Browse files
committed
Added TopNAgg csv tests for count and multiple aggs, which can be pushed down to lucene
1 parent 70095cf commit 54aec22

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
count
2+
from employees | stats c = count(height) | sort c | limit 100;
3+
4+
c:long
5+
100
6+
;
7+
8+
countGrouping
9+
from employees | stats c = count(height) by languages.long | sort languages.long | limit 100;
10+
11+
c:long | languages.long:long
12+
15 | 1
13+
19 | 2
14+
17 | 3
15+
18 | 4
16+
21 | 5
17+
10 | null
18+
;
19+
20+
multipleAggs
21+
from employees | stats c = count(height), m = max(height) | sort c | limit 100;
22+
23+
c:long | m:double
24+
100 | 2.1
25+
;
26+
27+
multipleAggsGrouping
28+
from employees | stats c = count(height), m = max(height) by languages.long | sort languages.long | limit 100;
29+
30+
c:long | m:double | languages.long:long
31+
15 | 2.06 | 1
32+
19 | 2.1 | 2
33+
17 | 2.1 | 3
34+
18 | 2.0 | 4
35+
21 | 2.1 | 5
36+
10 | 2.1 | null
37+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/PushStatsToSource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.elasticsearch.xpack.esql.expression.function.aggregate.Count;
2323
import org.elasticsearch.xpack.esql.optimizer.LocalPhysicalOptimizerContext;
2424
import org.elasticsearch.xpack.esql.optimizer.PhysicalOptimizerRules;
25-
import org.elasticsearch.xpack.esql.plan.physical.AggregateExec;
25+
import org.elasticsearch.xpack.esql.plan.physical.AbstractAggregateExec;
2626
import org.elasticsearch.xpack.esql.plan.physical.EsQueryExec;
2727
import org.elasticsearch.xpack.esql.plan.physical.EsStatsQueryExec;
2828
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
@@ -41,10 +41,10 @@
4141
/**
4242
* Looks for the case where certain stats exist right before the query and thus can be pushed down.
4343
*/
44-
public class PushStatsToSource extends PhysicalOptimizerRules.ParameterizedOptimizerRule<AggregateExec, LocalPhysicalOptimizerContext> {
44+
public class PushStatsToSource extends PhysicalOptimizerRules.ParameterizedOptimizerRule<AbstractAggregateExec, LocalPhysicalOptimizerContext> {
4545

4646
@Override
47-
protected PhysicalPlan rule(AggregateExec aggregateExec, LocalPhysicalOptimizerContext context) {
47+
protected PhysicalPlan rule(AbstractAggregateExec aggregateExec, LocalPhysicalOptimizerContext context) {
4848
PhysicalPlan plan = aggregateExec;
4949
if (aggregateExec.child() instanceof EsQueryExec queryExec) {
5050
var tuple = pushableStats(aggregateExec, context);
@@ -72,7 +72,7 @@ protected PhysicalPlan rule(AggregateExec aggregateExec, LocalPhysicalOptimizerC
7272
}
7373

7474
private Tuple<List<Attribute>, List<EsStatsQueryExec.Stat>> pushableStats(
75-
AggregateExec aggregate,
75+
AbstractAggregateExec aggregate,
7676
LocalPhysicalOptimizerContext context
7777
) {
7878
AttributeMap.Builder<EsStatsQueryExec.Stat> statsBuilder = AttributeMap.builder();

0 commit comments

Comments
 (0)