[ https://issues.apache.org/jira/browse/CALCITE-2346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16496639#comment-16496639 ]
Marc Prud'hommeaux edited comment on CALCITE-2346 at 5/31/18 2:35 PM: ---------------------------------------------------------------------- And I will lastly add that this issue can be worked around be explicitly casting the heterogeneous columns to the same type: {code:none} 0: jdbc:calcite:model=inline> select cast("DEPTNO" as int), "DNAME" from "scott"."DEPT" union all select cast("department_id" as int), "department_description" from "foodmart"."department" order by 1; +------------+--------------------------------+ | EXPR$0 | DNAME | +------------+--------------------------------+ | 1 | HQ General Management | | 2 | HQ Information Systems | | 3 | HQ Marketing | | 4 | HQ Human Resources | | 5 | HQ Finance and Accounting | | 10 | ACCOUNTING | | 11 | Store Management | | 14 | Store Information Systems | | 15 | Store Permanent Checkers | | 16 | Store Temporary Checkers | | 17 | Store Permanent Stockers | | 18 | Store Temporary Stockers | | 19 | Store Permanent Butchers | | 20 | RESEARCH | | 30 | SALES | | 40 | OPERATIONS | +------------+--------------------------------+ {code} was (Author: mprudhom): And I will lastly add that this issue can be worked around be explicitly casting the heterogeneous columns to the same type: {code:SQL} 0: jdbc:calcite:model=inline> select cast("DEPTNO" as int), "DNAME" from "scott"."DEPT" union all select cast("department_id" as int), "department_description" from "foodmart"."department" order by 1; +------------+--------------------------------+ | EXPR$0 | DNAME | +------------+--------------------------------+ | 1 | HQ General Management | | 2 | HQ Information Systems | | 3 | HQ Marketing | | 4 | HQ Human Resources | | 5 | HQ Finance and Accounting | | 10 | ACCOUNTING | | 11 | Store Management | | 14 | Store Information Systems | | 15 | Store Permanent Checkers | | 16 | Store Temporary Checkers | | 17 | Store Permanent Stockers | | 18 | Store Temporary Stockers | | 19 | Store Permanent Butchers | | 20 | RESEARCH | | 30 | SALES | | 40 | OPERATIONS | +------------+--------------------------------+ {code} > UNION results with different column types can cause ClassCastException > ---------------------------------------------------------------------- > > Key: CALCITE-2346 > URL: https://issues.apache.org/jira/browse/CALCITE-2346 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.16.0 > Environment: macOS 10.13.4 (17E202) > openjdk version "10" 2018-03-20 > OpenJDK Runtime Environment 18.3 (build 10+46) > OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode) > Reporter: Marc Prud'hommeaux > Assignee: Julian Hyde > Priority: Minor > > Trying to union results from two separate data types is throwing: > {code:java} > java.lang.ClassCastException: java.base/java.lang.Byte cannot be cast to > java.base/java.lang.Integer > at > org.apache.calcite.avatica.util.AbstractCursor$IntAccessor.getInt(AbstractCursor.java:545) > at org.apache.calcite.avatica.AvaticaSite.get(AvaticaSite.java:339) > at > org.apache.calcite.avatica.AvaticaResultSet.getObject(AvaticaResultSet.java:377) > at sqlline.Rows$Row.<init>(Rows.java:157) > at sqlline.IncrementalRows.hasNext(IncrementalRows.java:66) > at sqlline.TableOutputFormat.print(TableOutputFormat.java:33) > at sqlline.SqlLine.print(SqlLine.java:1648) > {code} > It can reproduced with the command: > {code:java} > coursier launch \ > sqlline:sqlline:1.4.0 \ > org.apache.calcite:calcite-core:1.16.0 \ > org.hsqldb:hsqldb:2.4.0 \ > net.hydromatic:scott-data-hsqldb:0.1 \ > net.hydromatic:foodmart-data-hsqldb:0.4 \ > -M sqlline.SqlLine -- \ > -d org.apache.calcite.jdbc.Driver \ > -u > 'jdbc:calcite:model=inline:{"version":1.0,"schemas":[{"name":"scott","type":"jdbc","jdbcUrl":"jdbc:hsqldb:res:scott","jdbcUser":"SCOTT","jdbcPassword":"TIGER"},{"name":"foodmart","type":"jdbc","jdbcSchema":"foodmart","jdbcUrl":"jdbc:hsqldb:res:foodmart"}]}' > > {code} > The following command works fine: > {code:java} > 0: jdbc:calcite:model=inline:{"version":1.0,"> select "DNAME" from > "scott"."DEPT" union all select "department_description" from > "foodmart"."department"; > +--------------------------------+ > | DNAME | > +--------------------------------+ > | ACCOUNTING | > | RESEARCH | > | SALES | > | OPERATIONS | > | HQ General Management | > | HQ Information Systems | > | HQ Marketing | > | HQ Human Resources | > | HQ Finance and Accounting | > | Store Management | > | Store Information Systems | > | Store Permanent Checkers | > | Store Temporary Checkers | > | Store Permanent Stockers | > | Store Temporary Stockers | > | Store Permanent Butchers | > +--------------------------------+ > 16 rows selected (0.069 seconds) > {code} > But when unioning two different column types: > {code:java} > 0: jdbc:calcite:model=inline:{"version":1.0,"> select "DEPTNO", "DNAME" from > "scott"."DEPT" union all select "department_id", "department_description" > from "foodmart"."department"; > +------------+--------------------------------+ > | DEPTNO | DNAME | > +------------+--------------------------------+ > java.lang.ClassCastException: java.base/java.lang.Byte cannot be cast to > java.base/java.lang.Integer > at > org.apache.calcite.avatica.util.AbstractCursor$IntAccessor.getInt(AbstractCursor.java:545) > at org.apache.calcite.avatica.AvaticaSite.get(AvaticaSite.java:339) > at > org.apache.calcite.avatica.AvaticaResultSet.getObject(AvaticaResultSet.java:377) > at sqlline.Rows$Row.<init>(Rows.java:157) > at sqlline.IncrementalRows.hasNext(IncrementalRows.java:66) > at sqlline.TableOutputFormat.print(TableOutputFormat.java:33) > at sqlline.SqlLine.print(SqlLine.java:1648) > at sqlline.Commands.execute(Commands.java:834) > at sqlline.Commands.sql(Commands.java:733) > at sqlline.SqlLine.dispatch(SqlLine.java:795) > {code} > Possibly related: https://issues.apache.org/jira/browse/CALCITE-580 -- This message was sent by Atlassian JIRA (v7.6.3#76005)