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

Mihai Budiu commented on CALCITE-6020:
--------------------------------------

If indeed your change is correct, then it uncovers a bug which I traced to this 
piece of code in RexBuilder.makeOver:

{code:java}
          makeCall(SqlStdOperatorTable.CASE,
              makeCall(SqlStdOperatorTable.GREATER_THAN,
                  new RexOver(bigintType, SqlStdOperatorTable.COUNT, exprs,
                      window, distinct, ignoreNulls),
                  makeLiteral(BigDecimal.ZERO, bigintType,
                      SqlTypeName.DECIMAL)),
              ensureType(type, // SUM0 is non-nullable, thus need a cast
                  new RexOver(typeFactory.createTypeWithNullability(type, 
false),
                      operator, exprs, window, distinct, ignoreNulls),
                  false),
              makeNullLiteral(type));
{code}

I don't think the type should be made nullable here.

> 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: Norman Jordan
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.38.0
>
>
> {{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