Skip to content

Commit

Permalink
SQL: Fix SUM(all zeroes) to return 0 instead of NULL (elastic#65796)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Andras Palinkas committed Dec 9, 2020
1 parent 5e90709 commit bf5d29c
Show file tree
Hide file tree
Showing 6 changed files with 547 additions and 29 deletions.
Loading

0 comments on commit bf5d29c

Please sign in to comment.