You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2020/12/07 19:33:00 UTC
[jira] [Resolved] (CALCITE-2198) ClassCastException in RexBuilder
when makeLiteral for BINARY and VARBINARY
[ https://issues.apache.org/jira/browse/CALCITE-2198?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Julian Hyde resolved CALCITE-2198.
----------------------------------
Fix Version/s: 1.27.0
Resolution: Not A Bug
Closing as 'not a bug' because there is already an acceptable way to create BINARY and VARBINARY literals. Instead of writing
{code}
literals.add((RexLiteral)
rexBuilder.makeLiteral(new byte[] {1, 2, -34, 0, -128},
typeFactory.createSqlType(SqlTypeName.BINARY, 5), false));
{code}
you should create a {{ByteString}}, as follows:
{code}
literals.add((RexLiteral)
rexBuilder.makeLiteral(new ByteString(new byte[] {1, 2, -34, 0, -128}),
typeFactory.createSqlType(SqlTypeName.BINARY, 5), false));
{code}
> 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
> Priority: Major
> Fix For: 1.27.0
>
>
> 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
(v8.3.4#803005)