[ https://issues.apache.org/jira/browse/CALCITE-6402?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17844737#comment-17844737 ]
Julian Hyde commented on CALCITE-6402: -------------------------------------- I agree with your analysis. It seems we need a means other than {{int groupCount}} to determine whether the output will contain rows that are the aggregate of zero rows. Can you propose something? I would be open to obsoleting {{groupCount}} (i.e. deprecating the method and ceasing to use it) and using something else. > Aggregates implied in grouping sets have a wrong nullability at validation > stage > -------------------------------------------------------------------------------- > > Key: CALCITE-6402 > URL: https://issues.apache.org/jira/browse/CALCITE-6402 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.36.0 > Reporter: Claude Brisson > Priority: Major > > As long as the empty set is present among the grouping sets, which is always > the case for CUBE and ROLLAP, the (unfiltered) result will contain a row with > the global aggregate. And on such a row, most standard aggregate functions > are nullable (even on a non-null column, for the empty rowset). > But the SUM function, for instance, has the following return type inference: > {code} > public static final SqlReturnTypeInference AGG_SUM = opBinding -> { > final RelDataTypeFactory typeFactory = opBinding.getTypeFactory(); > final RelDataType type = typeFactory.getTypeSystem() > .deriveSumType(typeFactory, opBinding.getOperandType(0)); > if (opBinding.getGroupCount() == 0 || opBinding.hasFilter()) { > return typeFactory.createTypeWithNullability(type, true); > } else { > return type; > } > }; > {code} > If the operand is not nullable, since the group count will be non-zero for a > rollup, a cube or a grouping sets containing the empty set. > It seems to me that the group count itself is not a sufficient information to > determine the nullability, we may be lacking a boolean stating whether the > empty group is implied, or the complete list of groups instead of the groups > count. -- This message was sent by Atlassian Jira (v8.20.10#820010)