[ 
https://issues.apache.org/jira/browse/CALCITE-6020?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17873751#comment-17873751
 ] 

Norman Jordan commented on CALCITE-6020:
----------------------------------------

I have played around with creating a new RelRule that looks at the project list 
and converts SUM to SUM0 for an OVER clause. The Rule is only applied when the 
project list contains an OVER clause with an SUM aggregate.

All of the tests pass except for SqlToRelConverterTests. The current change 
converts SUM to SUM0 during planning so it is expected that the 
SqlToRelConverterTests need to be updated.

SUM0 has value, but not everyone will want it. Some users find it necessary to 
convert SUM0 back to SUM, so we want an easy way to disable the SUM to SUM0 
conversion.

I'll post my code tomorrow as a proof of concept and see if we can work from 
there.

> SqlToRelConverter should not replace windowed SUM with equivalent expression 
> using SUM0
> ---------------------------------------------------------------------------------------
>
>                 Key: CALCITE-6020
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6020
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Zoltan Haindrich
>            Assignee: Zoltan Haindrich
>            Priority: Major
>              Labels: pull-request-available
>
> {{SqlToRelConverter}} replaces {{SUM}} with {{SUM0}} around 
> [here|https://github.com/apache/calcite/blob/e1991e08a225ef08c2402ab35c310d88fff3c222/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L5885]
> This might have been needed at some point in the past - but I think it will 
> be better to leave it as {{SUM}} - as in case there is no {{SUM0}} in the 
> system that will be replaced with a {{COALESCE(SUM(...) , 0 )}} to provide it 
> - as see 
> [here|https://github.com/apache/calcite/blob/e1991e08a225ef08c2402ab35c310d88fff3c222/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java#L1288]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to