Skip to content

SQL: do not attempt to canonicalize InnerAggregate#136854

Merged
luigidellaquila merged 2 commits intoelastic:mainfrom
luigidellaquila:sql/no_inner_aggregate_canonicalize
Oct 21, 2025
Merged

SQL: do not attempt to canonicalize InnerAggregate#136854
luigidellaquila merged 2 commits intoelastic:mainfrom
luigidellaquila:sql/no_inner_aggregate_canonicalize

Conversation

@luigidellaquila
Copy link
Contributor

InnerAggregate does not support replaceChildren(), so we should not try to canonicalize it either.

It's a very corner case, but it could happen (ref. ES-12727)

java.lang.UnsupportedOperationException: can't be rewritten at org.elasticsearch.xpack.ql.expression.function.aggregate.InnerAggregate.replaceChildren(InnerAggregate.java:51)
at org.elasticsearch.xpack.ql.expression.function.aggregate.InnerAggregate.replaceChildren(InnerAggregate.java:18)
at org.elasticsearch.xpack.ql.tree.Node.replaceChildrenSameSize(Node.java:231)
at org.elasticsearch.xpack.ql.expression.Expression.canonicalize(Expression.java:165)
at org.elasticsearch.xpack.ql.expression.Expression.canonical(Expression.java:151)
at org.elasticsearch.xpack.ql.expression.Expression.semanticHash(Expression.java:173)
at org.elasticsearch.xpack.ql.expression.predicate.BinaryOperator.canonicalize(BinaryOperator.java:55)
at org.elasticsearch.xpack.ql.expression.Expression.canonical(Expression.java:151)
at org.elasticsearch.xpack.ql.expression.Expression.semanticEquals(Expression.java:169)
at org.elasticsearch.xpack.sql.expression.predicate.conditional.NullIf.foldable(NullIf.java:57)

Unfortunately I don't have a reproducer (@bpintea probably you know this better than me, if you have ideas about this, I'll be happy to add a query to the tests)

@elasticsearchmachine elasticsearchmachine added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0 labels Oct 21, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Hi @luigidellaquila, I've created a changelog YAML for you.

@luigidellaquila luigidellaquila enabled auto-merge (squash) October 21, 2025 08:56
Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
I think SELECT NULLIF(PERCENTILE(0+salary+salary, 50), 0) FROM test_emp should do for a test.

@luigidellaquila luigidellaquila merged commit da9b1d6 into elastic:main Oct 21, 2025
34 checks passed
elasticsearchmachine pushed a commit that referenced this pull request Oct 22, 2025
Follow-up to #136854, just
adding a test
fzowl pushed a commit to voyage-ai/elasticsearch that referenced this pull request Nov 3, 2025
fzowl pushed a commit to voyage-ai/elasticsearch that referenced this pull request Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/SQL SQL querying >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0

3 participants