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

RexSimplify might remove CAST from RexNode incorrectly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.23.0, 1.24.0
    • 1.25.0
    • core

    Description

      @Test void testCastError() {
        final String sql = "select cast(cast(count(distinct empno) as varchar(65536)) as varbinary)\n"
            + "from emp group by deptno";
        sql(sql).ok();
      }
      

      Consider the above test case, we get the following plan after SqlToRel.

      LogicalProject(EXPR$0=[CAST($1):VARBINARY NOT NULL])
            LogicalAggregate(group=[{0}], agg#0=[COUNT(DISTINCT $1)])
              LogicalProject(DEPTNO=[$7], EMPNO=[$0])
                LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      

      As it is shown, `cast(* as varchar)` is removed (by RexSimplify#SimplifyCast), which is obviously wrong, because BIGINT can not cast to VARBINARY.

      Attachments

        Issue Links

          Activity

            People

              Chunwei Lei Chunwei Lei
              icshuo Shuo Cheng
              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 - 40m
                  40m