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

Julian Hyde commented on CALCITE-1595:
--------------------------------------

By the way, you should cast the argument. If you call {{RelBuilder.cast}} on a 
{{RexNode}} that happens to be a literal, it will convert the literal to 
another literal of the same type, if it can. For example, {{RexCall(CAST, 
INTEGER, RexLiteral(CHAR, "123")}} becomes {{RexLiteral(INTEGER, 123)}} but 
{{RexCall(CAST, INTEGER, RexLiteral(CHAR, "foo bar")}} remains unchanged and 
will give a runtime error.

> NPE in SqlTypeUtil
> ------------------
>
>                 Key: CALCITE-1595
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1595
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Jess Balint
>            Assignee: Julian Hyde
>            Priority: Minor
>
> I have some RelBuilder code building an expression something like {{\+(\+($0, 
> "30"), "30")}}. Yes, they are string literals :) This results in an NPE as 
> the type of {{+($0, "30")}} is _null_ and it hits the following code:
> {code}
>   public static boolean isExactNumeric(RelDataType type) {
>     SqlTypeName typeName = type.getSqlTypeName();
>     if (typeName == null) {
>       return false;
>     }
>     switch (typeName) {
> {code}
> Here's the stack:
> {noformat}
>         at 
> org.apache.calcite.sql.type.SqlTypeUtil.isExactNumeric(SqlTypeUtil.java:414)
>         at 
> org.apache.calcite.rel.type.RelDataTypeFactoryImpl.createDecimalQuotient(RelDataTypeFactoryImpl.java:521)
>         at 
> org.apache.calcite.sql.type.ReturnTypes$7.inferReturnType(ReturnTypes.java:464)
>         at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>         at 
> org.apache.calcite.sql.type.SqlReturnTypeInferenceChain.inferReturnType(SqlReturnTypeInferenceChain.java:56)
>         at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:469)
>         at 
> org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:271)
>         at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:245)
>         at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:529)
> {noformat}
> Where would be an appropriate place to add a new test for this? I'll get a PR 
> for this and the other stuff created soon.
> Thx.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to