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

RelFieldTrimmer incorrectly drops filter condition

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.29.0
    • None

    Description

      // code placeholder
      org.apache.calcite.test.SqlToRelConverterTest
      @Test void testTrim() {
        final String sql = "select count(*) from emp where ename = '1'";
        final RelNode rel = tester.convertSqlToRel(sql).rel;
        final HepProgramBuilder programBuilder = HepProgram.builder();
        programBuilder.addRuleInstance(CoreRules.FILTER_TO_CALC);
        final HepPlanner planner = new HepPlanner(programBuilder.build());
        planner.setRoot(rel);
        final RelNode calc = planner.findBestExp();
        final List<RelOptTable> relOptTables = RelOptUtil.findAllTables(calc);
        RelOptSchema relOptSchema = null;
        if (relOptTables.size() != 0) {
          relOptSchema = relOptTables.get(0).getRelOptSchema();
        }
        final RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(
            calc.getCluster(), relOptSchema);
        final RelFieldTrimmer fieldTrimmer = new RelFieldTrimmer(null, relBuilder);
        final RelNode trimmed = fieldTrimmer.trim(calc);
        System.out.println(RelOptUtil.toString(trimmed));
      }
      rel:
      LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
        LogicalProject($f0=[0])
          LogicalFilter(condition=[=($1, '1')])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]])
      
      trimmed:
      LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
        LogicalTableScan(table=[[CATALOG, SALES, EMP]])

       In this case,RelFieldTrimmer incorrectly drops filter condition.`RelNode(trimmed)` is incorrect,there is no predicate condition `ename = '1'` in final `RelNode(trimmed)`.During Calc operator trim, predicates should not be lost. 

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              xzh_dz xzh_dz
              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 - 50m
                  50m