danny0405 commented on a change in pull request #1460: [CALCITE-3352]
ProjectToWindowRule sets wrong collation on generated Window
URL: https://github.com/apache/calcite/pull/1460#discussion_r326974639
##########
File path: core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
##########
@@ -6122,6 +6122,56 @@ private Sql checkSubQuery(String sql) {
checkPlanning(FilterJoinRule.FILTER_ON_JOIN, query);
}
+ @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 ci =
r.getInput(0).getTraitSet().getTrait(RelCollationTraitDef.INSTANCE);
+ assertEquals("Window collation is incorrect", "[3, 7]", ci.toString());
+ RelCollation co = r.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE);
+ assertEquals("Project collation is incorrect", "[0, 1]", co.toString());
+ }
+
+ @Test public void testWindowOnSortedInput1() {
+ final HepProgram preProgram = new HepProgramBuilder()
+ .addRuleInstance(SortProjectTransposeRule.INSTANCE)
+ .build();
+ final HepProgram program = HepProgram.builder()
+ .addRuleInstance(ProjectToWindowRule.PROJECT)
+ .build();
Review comment:
The only different is the tester right ? Then we can merge these 2 tests
into one which is more intuitive.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services