[ https://issues.apache.org/jira/browse/CALCITE-3164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16878138#comment-16878138 ]
Muhammad Gelbana commented on CALCITE-3164: ------------------------------------------- You're correct. It turned out that my type-system is causing this. I overrode {{deriveSumType}} and {{deriveAvgAggType}} to return non nullable {{BIGINT}} and {{DOUBLE}} types respectively. After fixing those overrides tp return nullable types instead, the query started returning {{NULL}} as expected. > Averaging an all-nulls values after grouping produce NaN instead of NULL > ------------------------------------------------------------------------ > > Key: CALCITE-3164 > URL: https://issues.apache.org/jira/browse/CALCITE-3164 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.20.0 > Reporter: Muhammad Gelbana > Priority: Major > > {code:sql} > -- Values are a single tuple > SELECT C1, avg(C2) > FROM (VALUES('X', NULL::INT)) T (C1, C2) > GROUP BY C1 > -- Values are more than a single tuple > SELECT C1, avg(C2) > FROM (VALUES('X', NULL::INT), ('X', NULL::INT)) T (C1, C2) > GROUP BY C1 > {code} > Those queries return {{NaN}} while it's expected to return {{NULL}}. -- This message was sent by Atlassian JIRA (v7.6.3#76005)