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

FilterProjectTransposeRule generates wrong traitSet when copyFilter/Project is true

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.18.0
    • 1.20.0
    • None

    Description

      Problem can be reproduced with the following steps:

      As suggested by zabetak, a possibility to reproduce this issue is with the following test in RelOptRulesTest:

        /** Test case for
         * <a href="https://issues.apache.org/jira/browse/CALCITE-2865">[CALCITE-2865]
         * FilterProjectTransposeRule generates wrong traitSet when copyFilter/Project is true</a>. */
        @Test public void testFilterProjectTransposeRule() {
          List<RelOptRule> rules = Arrays.asList(
                  FilterProjectTransposeRule.INSTANCE, // default values: copyFilter=true, copyProject=true
                  new FilterProjectTransposeRule(Filter.class, Project.class, /*copyFilter*/ false, /*copyProject*/ false, RelFactories.LOGICAL_BUILDER));
      
          List<RelNode> results = new ArrayList<>(2);
      
          for (RelOptRule rule : rules) {
            RelBuilder b = RelBuilder.create(RelBuilderTest.config().build());
            RelNode in = b
                    .scan("EMP")
                    .sort(-4) // salary desc
                    .project(b.field(3)) // salary
                    .filter(b.equals(b.field(0), b.literal(11500))) // salary = 11500
                    .build();
            HepProgram program = new HepProgramBuilder()
                    .addRuleInstance(rule)
                    .build();
            HepPlanner hepPlanner = new HepPlanner(program);
            hepPlanner.setRoot(in);
            results.add(hepPlanner.findBestExp());
          }
          // compare LogicalFilter traitSet
          assertEquals(results.get(0).getInput(0).getTraitSet(), results.get(1).getInput(0).getTraitSet());
        }
      

      Which fails with the following message:

      java.lang.AssertionError: 
      Expected :NONE.[0 DESC]
      Actual   :NONE.[3 DESC]
      

      If we run the test with a break point at the end of FilterProjectTransposeRule#onMatch method, we can see that, when the project and filter are transposed, the generated output (newFilterRel) is different in terms of traitSet, depending if the copyFilter / copyProject flags are used or not:

      • copyFilter and copyProject TRUE (default)
        LogicalProject.NONE.[0 DESC] 
            LogicalFilter.NONE.[0 DESC] // !!! 
                LogicalSort.NONE.[3 DESC] 
        
      • copyFilter and copyProject FALSE
        LogicalProject.NONE.[0 DESC] 
            LogicalFilter.NONE.[3 DESC] // !!! 
                LogicalSort.NONE.[3 DESC] 
        

      As I see it, the default behavior (copyFilter/Project true) seems wrong in terms of new filter's traitSet.

      Attachments

        Issue Links

          Activity

            People

              rubenql Ruben Q L
              rubenql Ruben Q L
              Votes:
              0 Vote for this issue
              Watchers:
              4 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 - 2h 40m
                  2h 40m