Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.21.0
-
None
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
- links to