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 09:17:00 UTC

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

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

Limian Zhang updated CALCITE-4498:
----------------------------------
    Description: 
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;

 

 
  

  was:
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;

 

 
 


> leastRestrictiveStructuredType in RelDataTypeFactoryImpl is buggy
> -----------------------------------------------------------------
>
>                 Key: CALCITE-4498
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4498
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.26.0
>         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;
>  
>  
>   



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