Pavel Gubin created CALCITE-3352:

             Summary: ProjectToWindowRule sets wrong collation on generated 
                 Key: CALCITE-3352
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.21.0
            Reporter: Pavel Gubin

{{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(

    final HepProgram preProgram = new HepProgramBuilder()
    final HepProgram program = HepProgram.builder()

    final String sql = "select mgr, deptno, sum(sal) over (partition by 
        + "from emp\n"
        + "order by mgr, deptno";

    RelNode r = checkPlanning(tester, preProgram, new HepPlanner(program), sql);
    RelCollation c = 
    assertEquals("Collation is incorrect", "[3, 7]", c.toString());

This message was sent by Atlassian Jira

Reply via email to