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

Julian Hyde edited comment on CALCITE-6402 at 5/8/24 6:41 PM:
--------------------------------------------------------------

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.

When implementing CALCITE-704, I [commented 
that|https://github.com/apache/calcite/blob/7ef829e17cf382e34b2c5ee36a664d98a7258c31/core/src/main/java/org/apache/calcite/sql/SqlFilterOperator.java#L103]
 that "[pretending that group-count is 0] tells the aggregate function that it 
might be invoked with 0 rows in a group". I think we should continue with that 
approach, or maybe make it more explicit.



was (Author: julianhyde):
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)

Reply via email to