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

RelMetadataQuery.getColumnOrigins should return null when column origin includes correlation variables

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • 1.39.0
    • None

    Description

      The Correlate is not currently supported when metadata gets the column origin.(RelMdColumnOrigins#getColumnOrigins)

      If a column is processed from a correlation variable, the correlation variable is ignored and the rest of the columns are returned.

      In fact, we should return null for cases that cannot be determined.

      @Test void testColumnOriginsForCorrelate() {
        final String sql = "select (select max(dept.name || '_' || emp.ename)"
            + "from dept where emp.deptno = dept.deptno) from emp";
        final RelMetadataFixture fixture = sql(sql);
      
        final HepProgramBuilder programBuilder = HepProgram.builder();
        programBuilder.addRuleInstance(CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE);
        final HepPlanner planner = new HepPlanner(programBuilder.build());
        planner.setRoot(fixture.toRel());
        final RelNode optimizedRel = planner.findBestExp();
      
        fixture.withRelTransform(a -> optimizedRel.getInput(0).getInput(1))
            .assertColumnOriginSingle("DEPT", "NAME", true);
      } 

      OptimizeRel:

      LogicalProject(EXPR$0=[$9])
        LogicalCorrelate(correlation=[$cor1], joinType=[left], requiredColumns=[{1, 7}])
          LogicalTableScan(table=[[CATALOG, SALES, EMP]])
          LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
            LogicalProject($f0=[||(||($1, '_'), $cor1.ENAME)])
              LogicalFilter(condition=[=($cor1.DEPTNO, $0)])
                LogicalTableScan(table=[[CATALOG, SALES, DEPT]])

      Attachments

        Activity

          People

            suibianwanwan33 suibianwanwan
            suibianwanwan33 suibianwanwan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: