Skip to content

ESQL: Verifier failure to catch aggregation functions outside STATS command #124311

@astefan

Description

@astefan

Description

In theory, the Verifier should prevent queries that use aggregation functions to be used outside an aggregation "context", meaning the stats command. For example, from employees | eval x = min(languages) returns a 400 error message

line 1:27: aggregate function [min(languages)] not allowed outside STATS command

While from employees | where min(languages) > 2 returns a 500 error:

path: /_query, params: {format=txt, error_trace=true}, status: 500 org.elasticsearch.xpack.esql.core.QlIllegalArgumentException: Unsupported expression [min(languages)]
        at org.elasticsearch.xpack.esql.evaluator.EvalMapper.toEvaluator(EvalMapper.java:96)
        at org.elasticsearch.xpack.esql.evaluator.EvalMapper$1.apply(EvalMapper.java:77)
        at org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.EsqlBinaryComparison.toEvaluator(EsqlBinaryComparison.java:227)
        at org.elasticsearch.xpack.esql.evaluator.EvalMapper.toEvaluator(EvalMapper.java:74)
        at org.elasticsearch.xpack.esql.planner.LocalExecutionPlanner.planFilter(LocalExecutionPlanner.java:700)

The failure to map the where command shouldn't happen, instead the behavior should be caught early on by the Verifier, just like the first scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions