Skip to content

Commit d592461

Browse files
committed
Fix detecting stats query
1 parent 529a3f0 commit d592461

File tree

1 file changed

+3
-6
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/local

1 file changed

+3
-6
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,10 @@ protected PhysicalPlan rule(AggregateExec aggregateExec, LocalPhysicalOptimizerC
5050
var tuple = pushableStats(aggregateExec, context);
5151

5252
// for the moment support pushing count just for one field
53-
List<EsStatsQueryExec.Stat> stats = tuple.v2();
54-
if (stats.size() != 1) {
55-
return aggregateExec;
56-
}
57-
5853
// TODO: handle case where some aggs cannot be pushed down by breaking the aggs into two sources (regular + stats) + union
5954
// use the stats since the attributes are larger in size (due to seen)
60-
if (tuple.v2().size() == aggregateExec.aggregates().size()) {
55+
List<EsStatsQueryExec.Stat> stats = tuple.v2();
56+
if (stats.size() == 1 && tuple.v2().size() == aggregateExec.aggregates().size()) {
6157
plan = new EsStatsQueryExec(
6258
aggregateExec.source(),
6359
queryExec.indexPattern(),
@@ -70,6 +66,7 @@ protected PhysicalPlan rule(AggregateExec aggregateExec, LocalPhysicalOptimizerC
7066
}
7167

7268
// TODO: what is a good place to do something like this?
69+
// TODO: this exception ends up in the execution info in the API response; fix that
7370
if (context.configuration().throwOnNonEsStatsQuery() && plan instanceof EsStatsQueryExec == false) {
7471
throw new UnsupportedOperationException("not executing query of type [" + plan.getClass().getSimpleName() + "]");
7572
}

0 commit comments

Comments
 (0)