Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2346

UNION results with different column types can cause ClassCastException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.16.0
    • None
    • core
    • None
    • 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)

    Description

      Trying to union results from two separate data types is throwing:

      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)
      
      

      It can reproduced with the command:

      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"}]}' 
      

      The following command works fine:

      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)
      

      But when unioning two different column types:

      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)
      

      Possibly related: https://issues.apache.org/jira/browse/CALCITE-580

      Attachments

        Activity

          People

            Unassigned Unassigned
            mprudhom Marc Prud'hommeaux
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: