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

IN-list converted to JOIN throws type mismatch exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.26.0, 1.27.0
    • 1.30.0
    • core
    • jdk8

       

    Description

      The sql query is 

      SELECT * FROM (
      SELECT '20210101' AS dt, deptno
      FROM emp
      GROUP BY deptno
      ) t
      WHERE cast(deptno as varchar) in ('1')
      
      

      When Calcite converts the IN list to JOIN, the original leaf rel will be replaced by a new rel, but the new rel hasn't been set as a leaf rel, This will cause mismatched field type.

      Finally, the query results

      java.lang.AssertionError: Conversion to relational algebra failed to preserve datatypes:
      validated type:
      RecordType(CHAR(8) NOT NULL dt, INTEGER deptno) NOT NULL
      converted type:
      RecordType(INTEGER dt, INTEGER deptno) NOT NULL
      rel:
      LogicalProject(dt=[$0], deptno=[$1])
        LogicalJoin(condition=[=($2, $3)], joinType=[inner])
          LogicalProject(dt=['20210101'], deptno=[$0], deptno0=[CAST($0):VARCHAR])
            LogicalAggregate(group=[\{0}])
              LogicalProject(deptno=[$1])
                HiveTableScan(table=[[default, emp]])
          LogicalAggregate(group=[\{0}])
            LogicalValues(tuples=[[\{ '1' }]])    at org.apache.calcite.sql2rel.SqlToRelConverter.checkConvertedType(SqlToRelConverter.java:467)
          at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:582)

      Attachments

        Issue Links

          Activity

            People

              yanjing.wang yanjing.wang
              yanjing.wang yanjing.wang
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2.5h
                  2.5h