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

Mehant Baid commented on CALCITE-547:
-------------------------------------

Yes count is always non-nullable, however count of a nullable column versus a 
non-nullable column is the issue here.
Consider following query 
select count(t.col1['col2'])  from foo as t; 

Calcite transforms this query to 
select count(0) from foo as t

This causes wrong results since we end up including the nulls in the count as 
well. The reason this transformation happens is because the nullability of the 
item operator is set to false. 



> Fix return type of item operator when operand type is not known
> ---------------------------------------------------------------
>
>                 Key: CALCITE-547
>                 URL: https://issues.apache.org/jira/browse/CALCITE-547
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Mehant Baid
>            Assignee: Mehant Baid
>         Attachments: CALCITE-547.patch
>
>
> While inferring the return type of the item operator (SqlItemOperator. 
> inferReturnType()) when the SqlTypeName of the operand is ANY we set the 
> nullability of return type to be false. Since the type of the operand is not 
> known at this point we cannot know the return type and its nullability.
> Setting nullability to false was causing wrong results in Drill when we were 
> performing count(item op), Calcite would set nullability to be false and the 
> count(item op) would get replaced with count(0) causing wrong results if the 
> column is eventually resolved to be nullable and has nulls in it.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to