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

Julian Hyde commented on CALCITE-2198:
--------------------------------------

Why stop at {{byte[]}}? Why not add {{ByteBuffer}} and {{InputStream}}? If you 
can't tell, I'm joking. There needs to be one supported value type per SQL 
type, and for {{BINARY}} and {{VARBINARY}} that type is {{ByteString}}. It's 
easy to create a {{ByteString}} from a {{byte[]}} value: {{new 
ByteString(bytes)}}. If you want other types, you can create wrappers in your 
own code.

I do see that our documentation needs to be improved. It was reasonable for you 
to assume that {{makeLiteral}} would accept {{byte[]}} because that is the most 
obvious type (it is the one used by JDBC, for example). And a 
{{ClassCastException}} was not the right way to tell you that you got it wrong. 
So we need documentation spelling out what the method expects.

> ClassCastException in RexBuilder when makeLiteral for BINARY and VARBINARY
> --------------------------------------------------------------------------
>
>                 Key: CALCITE-2198
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2198
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Hequn Cheng
>            Assignee: Julian Hyde
>            Priority: Major
>
> Currently, makeLiteral for {{BINARY}} and {{VARBINARY}} will throw 
> {{ClassCastException}} when value type is {{byte[]}}:
> {code:java}
> java.lang.ClassCastException: [B cannot be cast to 
> org.apache.calcite.avatica.util.ByteString
> at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:1336)
> at 
> org.apache.calcite.test.RexProgramTest.testSimplifyCastLiteral(RexProgramTest.java:1567){code}
> The exception can be reproduced by the following test case(in 
> RexProgramTest.testSimplifyCastLiteral()):
> {code:java}
> literals.add((RexLiteral)
>     rexBuilder.makeLiteral(new byte[] {1, 2, -34, 0, -128},
>         typeFactory.createSqlType(SqlTypeName.BINARY, 5), false));{code}
> To avoid this exception we have to add support for type of  {{byte[]}}. One 
> choice is to convert {{byte[]}} to {{ByteString}} in {{RexBuilder.clean()}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to