Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Fix SUM(all zeroes) to return 0 instead of NULL (#65796) #66129

Merged
merged 1 commit into from
Dec 9, 2020

Conversation

palesz
Copy link
Contributor

@palesz palesz commented Dec 9, 2020

Previously the SUM(all zeroes) was NULL, but after this change the SUM
SQL function call is automatically upgraded into a stats aggregation
instead of a sum aggregation. The stats aggregation only results in
NULL if the there were no rows, no values (all nulls) to aggregate, which
is the expected behaviour across different SQL implementations.

This is a workaround for the issue #45251 . Once the results of the sum
aggregation can differentiate between SUM(all nulls) and
SUM(all zeroes) the optimizer rule introduced in this commit needs to be
removed.

(cherry-picked from b74792a)

Previously the SUM(all zeroes) was `NULL`, but after this change the SUM
SQL function call is automatically upgraded into a `stats` aggregation
instead of a `sum` aggregation. The `stats` aggregation only results in
`NULL` if the there were no rows, no values (all nulls) to aggregate, which
is the expected behaviour across different SQL implementations.

This is a workaround for the issue elastic#45251 . Once the results of the `sum`
aggregation can differentiate between `SUM(all nulls)` and
`SUM(all zeroes`) the optimizer rule introduced in this commit needs to be
removed.

(cherry-picked from b74792a)
@palesz palesz added :Analytics/SQL SQL querying backport Team:QL (Deprecated) Meta label for query languages team v7.11.0 labels Dec 9, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@palesz palesz merged commit bca021a into elastic:7.x Dec 9, 2020
@palesz palesz deleted the fix/sum-null-7x branch December 9, 2020 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying backport Team:QL (Deprecated) Meta label for query languages team v7.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants