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

ProjectToWindowRule sets wrong collation on generated Window

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.21.0
    • None
    • core

    Description

      ProjectToWindowRule sets the collocation of the Project it applies to on the generated LogicalWindow which is wrong, because the collation of the input can be different and Window doesn't change the collation. So the collation of the generated LogicalWindow should be the same as on the input (not the output).

      The following test in RelOptRulesTest reproduces the issue:

        @Test public void testWindowOnSortedInput() {
          // Create a customized test with RelCollation trait in the test cluster.
          Tester tester = new TesterImpl(getDiffRepos(), true, true, false, false,
              true, null, null) {
            @Override public RelOptPlanner createPlanner() {
              return new MockRelOptPlanner(Contexts.empty()) {
                @Override public List<RelTraitDef> getRelTraitDefs() {
                  return ImmutableList.of(RelCollationTraitDef.INSTANCE);
                }
                @Override public RelTraitSet emptyTraitSet() {
                  return RelTraitSet.createEmpty().plus(
                      RelCollationTraitDef.INSTANCE.getDefault());
                }
              };
            }
          };
      
          final HepProgram preProgram = new HepProgramBuilder()
              .addRuleInstance(SortProjectTransposeRule.INSTANCE)
              .build();
          final HepProgram program = HepProgram.builder()
              .addRuleInstance(ProjectToWindowRule.PROJECT)
              .build();
      
          final String sql = "select mgr, deptno, sum(sal) over (partition by deptno)\n"
              + "from emp\n"
              + "order by mgr, deptno";
      
          RelNode r = checkPlanning(tester, preProgram, new HepPlanner(program), sql);
          RelCollation c = r.getInput(0).getTraitSet().getTrait(RelCollationTraitDef.INSTANCE);
          assertEquals("Collation is incorrect", "[3, 7]", c.toString());
        }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Pavel Gubin Pavel Gubin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 40m
                  2h 40m