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

Do not push 'cast to not null' through Join in ProjectJoinTransposeRule

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.33.0
    • None

    Description

      I meet a bug, when applying rule of 'ProjectJoinTransposeRule'.

      Test Case:

      @Test void testPushProjectPastLeftJoin2() {
        final String sql = "select coalesce(d.name, b.job, '')\n"
            + "from emp e\n"
            + "left join bonus b on e.ename = b.ename\n"
            + "left join dept d on e.deptno = d.deptno";
        sql(sql).withRule(CoreRules.PROJECT_JOIN_TRANSPOSE).check();
      } 

      Exception Stack:

      Suppressed: java.lang.AssertionError: Cannot add expression of different type to set:
      set type is RecordType(INTEGER NOT NULL DEPTNO, BOOLEAN NOT NULL EXPR$0, VARCHAR(10) NOT NULL EXPR$1) NOT NULL
      expression type is RecordType(INTEGER NOT NULL DEPTNO, BOOLEAN NOT NULL EXPR$0, VARCHAR(10) EXPR$1) NOT NULL
      set is rel#20:LogicalProject.(input=HepRelVertex#14,exprs=[$7, IS NOT NULL($10), CAST($10):VARCHAR(10) NOT NULL])
      expression is LogicalProject(DEPTNO=[$1], EXPR$0=[IS NOT NULL($3)], EXPR$1=[$4])
        LogicalJoin(condition=[=($0, $2)], joinType=[left])
          LogicalProject(ENAME=[$1], DEPTNO=[$7])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalProject(ENAME=[$0], JOB=[$1], EXPR$1=[$1])
            LogicalTableScan(table=[[CATALOG, SALES, BONUS]]) 

      I found that right with wrap not-null shouldn't be push down in one stage.

       

      // before applying rule
      LogicalProject(DEPTNO=[$7], EXPR$0=[IS NOT NULL($10)], EXPR$1=[CAST($10):VARCHAR(10) NOT NULL])
        LogicalJoin(condition=[=($1, $9)], joinType=[left])
          LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
      
      // after applying rule
      LogicalProject(DEPTNO=[$1], EXPR$0=[IS NOT NULL($3)], EXPR$1=[$4])
        LogicalJoin(condition=[=($0, $2)], joinType=[left])
          LogicalProject(ENAME=[$1], DEPTNO=[$7])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalProject(ENAME=[$0], JOB=[$1], EXPR$1=[$1])
            LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
       

      `EXPR$1=[CAST($10):VARCHAR(10) NOT NULL]` should be pushed down, because of left-join.

       

       

      Attachments

        Issue Links

          Activity

            People

              wojustme Xurenhe
              wojustme Xurenhe
              Votes:
              0 Vote for this issue
              Watchers:
              6 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 - 4h
                  4h