[
https://issues.apache.org/jira/browse/CALCITE-6621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17888084#comment-17888084
]
Julian Hyde commented on CALCITE-6621:
--------------------------------------
Could we obsolete the {{nullWhenCountZero}} field altogether? It seems that
{{nullWhenCountZero}} is always equal to {{operator.getKind() == SqlKind.SUM &&
type.isNullable()}}, and it seems to be useful only for certain implementations
(e.g. computing a sum using a Java {{int}} accumulator).
> RexBuilder.makeOver() should not try to nullify a null result
> -------------------------------------------------------------
>
> Key: CALCITE-6621
> URL: https://issues.apache.org/jira/browse/CALCITE-6621
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.38.0
> Reporter: Claude Brisson
> Priority: Minor
>
> This is probably linked to CALCITE-6020.
> In a window function that uses the nullable {{SUM}} aggregation operator,
> {{RexBuilder.makeOver()}} will produce the following construct:
> {code:java}
> CASE((COUNT($0) OVER (...), 0), SUM($0) OVER (...), null:BIGINT) {code}
> which is both useless and inefficient.
> Using this construct should only be done for non-nullable aggregation
> operators like {{SUM0}} (that's the only one I can think of).
> The workaround is to inherit {{RexBuilder}} and override {{makeOver() }}as
> follow:
> {code:java}
> public RexNode makeOver(
> RelDataType type,
> SqlAggFunction operator,
> List<RexNode> exprs,
> List<RexNode> partitionKeys,
> ImmutableList<RexFieldCollation> orderKeys,
> RexWindowBound lowerBound,
> RexWindowBound upperBound,
> RexWindowExclusion exclude,
> boolean rows,
> boolean allowPartial,
> boolean nullWhenCountZero,
> boolean distinct,
> boolean ignoreNulls) {
> return super.makeOver(
> type,
> operator,
> exprs,
> partitionKeys,
> orderKeys,
> lowerBound,
> upperBound,
> exclude,
> rows,
> allowPartial,
> nullWhenCountZero && operator.getKind() == SqlKind.SUM0,
> distinct,
> ignoreNulls
> );
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)