[
https://issues.apache.org/jira/browse/CALCITE-4498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17284034#comment-17284034
]
Julian Hyde commented on CALCITE-4498:
--------------------------------------
Your new title, "Exception in thread "main" java.lang.NullPointerException at
org.apache.calcite.rel.type.RelDataTypeImpl.getFieldCount(RelDataTypeImpl.java:156)"
is a *symptom*, but the title should be the *problem*. What was the user was
trying to do that didn't work? E.g. 'Cannot deduce type of CASE expression that
returns a STRUCT'.
The symptom (i.e. the stack trace) is already in the description, so people
will find it when they search.
> 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}} gets 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.
> stack trace:
> {code:java}
> Exception in thread "main" java.lang.NullPointerException
> at
> org.apache.calcite.rel.type.RelDataTypeImpl.getFieldCount(RelDataTypeImpl.java:156)
> at
> org.apache.calcite.rel.type.RelDataTypeFactoryImpl.leastRestrictiveStructuredType(RelDataTypeFactoryImpl.java:223)
> at
> org.apache.calcite.sql.type.SqlTypeFactoryImpl.leastRestrictiveSqlType(SqlTypeFactoryImpl.java:285)
> at
> org.apache.calcite.sql.type.SqlTypeFactoryImpl.leastRestrictive(SqlTypeFactoryImpl.java:156)
> {code}
> 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)