Limian Zhang created CALCITE-4498:
-------------------------------------
Summary: 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
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)