[
https://issues.apache.org/jira/browse/CALCITE-2820?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16782271#comment-16782271
]
Haisheng Yuan commented on CALCITE-2820:
----------------------------------------
I am curious too. Maybe because AVG, COVAR_POP, COVAR_SAMP, VAR_POP, etc. All
these aggregate functions will be rewritten to expressions with SUM. If we
continue reduce SUM to SUM0 and COUNT, and with a project on top, that would
make it more complex. [~julianhyde] Can you explain the reason to reduce SUM? I
can only find the commit message, but link does't work anymore.
Fix https://github.com/julianhyde/optiq/issues/232, "Sum and avg of empty set
should be null as per SQL specification". We achieve this by replacing
'SUM(x)' by 'CASE COUNT(*) = 0 THEN NULL ELSE SUM0(x) END' if it is possible
for the group to be empty (either x is nullable or the aggregate query applies
to the whole table), where SUM0 is an aggregate operator similar to SUM but
returns 0 if applied to the empty set.
> Add a version of AggregateReduceFunctionsRule that does not reduce SUm -> SUM0
> ------------------------------------------------------------------------------
>
> Key: CALCITE-2820
> URL: https://issues.apache.org/jira/browse/CALCITE-2820
> Project: Calcite
> Issue Type: Task
> Components: core
> Reporter: Siddharth Teotia
> Priority: Minor
> Labels: pull-request-available
> Time Spent: 1h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)