You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2021/02/12 16:29:00 UTC

[jira] [Commented] (CALCITE-4498) leastRestrictiveStructuredType in RelDataTypeFactoryImpl is buggy

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

Julian Hyde commented on CALCITE-4498:
--------------------------------------

Can you change the title to reflect the actual bug you have found? That will make the release notes more useful.

> leastRestrictiveStructuredType in RelDataTypeFactoryImpl is buggy
> -----------------------------------------------------------------
>
>                 Key: CALCITE-4498
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4498
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>         Environment: jvm 1.8.0_121
>            Reporter: Limian Zhang
>            Priority: Major
>
> in [code1|https://github.com/apache/calcite/blob/404f968f6079360621896e6ee20ec12488a40bc2/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java#L291] and [code2|https://github.com/apache/calcite/blob/f1da65504e598928cf77aa6a7244552692ae2529/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java#L224] the {{types}} could well be a List of [NULL (not java null point but SqlTypeName.NULL), Row], thus when this {{types}} will be passed down at code1 to code2, and in code 2 line 225, if you try to call `type0.getFieldCount();` You will hit a NullPointerException since the NULL SQL type has NULL as fieldList, thus calling `getFieldCount` will throw NPE.
> The above scenario could happen when we try to derive the type of a SqlCaseCall ([e.g.|https://github.com/apache/calcite/blob/f1da65504e598928cf77aa6a7244552692ae2529/core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java#L172]) where it's like this and we will call the above code path.
> CASE
>      WHEN _condition1_ THEN _NULL_
>      ELSE Some_StructType_
>  END;
>  
> basically i think the fix should be in code2, ignore the NULL type in the {{types}}, and only go through the non-null types to get the least restrictive.
>  
>  
>   



--
This message was sent by Atlassian Jira
(v8.3.4#803005)