chunweilei commented on a change in pull request #2011:
URL: https://github.com/apache/calcite/pull/2011#discussion_r437827477
##########
File path: core/src/test/java/org/apache/calcite/test/TopDownOptTest.java
##########
@@ -573,6 +575,112 @@
.removeRule(EnumerableRules.ENUMERABLE_SORT_RULE)
.check();
}
+
+ // test if "order by mgr desc nulls last" can be pushed through the calc
("select mgr").
+ @Test void testSortCalc() {
+ final String sql = "select mgr from sales.emp order by mgr desc nulls
last";
+ Query.create(sql)
+ .addRule(ProjectToCalcRule.INSTANCE)
+ .addRule(EnumerableRules.ENUMERABLE_CALC_RULE)
+ .removeRule(EnumerableRules.ENUMERABLE_SORT_RULE)
+ .removeRule(EnumerableRules.ENUMERABLE_PROJECT_RULE)
+ .check();
+ }
+
+ // test that Sort cannot push through calc because of non-trival call
+ // (e.g. RexCall(sal * -1)). In this example, the reason is that "sal * -1"
+ // creates opposite ordering if Sort is pushed down.
+ @Test void testSortCalcOnRexCall() {
+ final String sql = "select ename, sal * -1 as sal, mgr from\n"
+ + "sales.emp order by ename desc, sal desc, mgr desc nulls last";
+ Query.create(sql)
+ .addRule(ProjectToCalcRule.INSTANCE)
+ .addRule(EnumerableRules.ENUMERABLE_CALC_RULE)
+ .removeRule(EnumerableRules.ENUMERABLE_SORT_RULE)
+ .removeRule(EnumerableRules.ENUMERABLE_PROJECT_RULE)
+ .check();
+ }
+
+ // test that Sort can push through calc when cast is monotonic.
+ @Test void testSortCalcWhenCastLeadingToMonotonic() {
+ final String sql = "select deptno from sales.emp order by cast(deptno as
float) desc";
Review comment:
Makes sense.
----------------------------------------------------------------
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]