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

[jira] [Updated] (CALCITE-4498) Exception in thread "main" java.lang.NullPointerException at org.apache.calcite.rel.type.RelDataTypeImpl.getFieldCount(RelDataTypeImpl.java:156)

     [ https://issues.apache.org/jira/browse/CALCITE-4498?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Limian Zhang updated CALCITE-4498:
----------------------------------
    Summary: Exception in thread "main" java.lang.NullPointerException at org.apache.calcite.rel.type.RelDataTypeImpl.getFieldCount(RelDataTypeImpl.java:156)  (was: leastRestrictiveStructuredType in RelDataTypeFactoryImpl is buggy)

> Exception in thread "main" java.lang.NullPointerException at org.apache.calcite.rel.type.RelDataTypeImpl.getFieldCount(RelDataTypeImpl.java:156)
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 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)