amaliujia commented on a change in pull request #1985:
URL: https://github.com/apache/calcite/pull/1985#discussion_r429584061



##########
File path: core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml
##########
@@ -35,6 +35,73 @@ EnumerableLimit(fetch=[5])
   EnumerableSortedAggregate(group=[{3}], EXPR$1=[COUNT()])
     EnumerableSort(sort0=[$3], dir0=[DESC-nulls-last])
       EnumerableTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testSortProject">
+        <Resource name="sql">
+            <![CDATA[select mgr from sales.emp order by mgr desc nulls last]]>
+        </Resource>
+        <Resource name="planBefore">
+            <![CDATA[
+LogicalSort(sort0=[$0], dir0=[DESC-nulls-last])
+  LogicalProject(MGR=[$3])
+    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+        <Resource name="planAfter">
+            <![CDATA[
+EnumerableProject(MGR=[$3])
+  EnumerableSort(sort0=[$3], dir0=[DESC-nulls-last])
+    EnumerableTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testSortProjectWhenCastLeadingToNoTMonotonic">
+        <Resource name="sql">
+            <![CDATA[select deptno from sales.emp order by cast(deptno as 
varchar) desc]]>
+        </Resource>
+        <Resource name="planBefore">
+            <![CDATA[
+LogicalSort(sort0=[$1], dir0=[DESC])
+  LogicalProject(DEPTNO=[$7], EXPR$1=[CAST($7):VARCHAR NOT NULL])
+    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+        <Resource name="planAfter">
+            <![CDATA[
+EnumerableSort(sort0=[$1], dir0=[DESC])
+  EnumerableProject(DEPTNO=[$7], EXPR$1=[CAST($7):VARCHAR NOT NULL])
+    EnumerableTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testSortFilter">
+        <Resource name="sql">
+            <![CDATA[
+select ename, job, mgr, max_sal from
+(select ename, job, mgr, max(sal) as max_sal from sales.emp group by ename, 
job, mgr) as t
+where max_sal > 1000
+order by mgr desc, max_sal
+]]>
+        </Resource>
+        <Resource name="planBefore">
+            <![CDATA[
+LogicalSort(sort0=[$2], sort1=[$3], dir0=[DESC], dir1=[ASC])
+  LogicalProject(ENAME=[$0], JOB=[$1], MGR=[$2], MAX_SAL=[$3])
+    LogicalFilter(condition=[>($3, 1000)])
+      LogicalAggregate(group=[{0, 1, 2}], MAX_SAL=[MAX($3)])
+        LogicalProject(ENAME=[$1], JOB=[$2], MGR=[$3], SAL=[$5])
+          LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+        <Resource name="planAfter">
+            <![CDATA[
+EnumerableSort(sort0=[$2], sort1=[$3], dir0=[DESC], dir1=[ASC])
+  EnumerableFilter(condition=[>($3, 1000)])
+    EnumerableSortedAggregate(group=[{1, 2, 3}], MAX_SAL=[MAX($5)])
+      EnumerableSort(sort0=[$1], sort1=[$2], sort2=[$3], dir0=[ASC], 
dir1=[ASC], dir2=[ASC])
+        EnumerableTableScan(table=[[CATALOG, SALES, EMP]])

Review comment:
       Test whether EnumerableFilter can push down collation. 
   
   To refresh memory a bit, this test used to generated something like the 
following by a single select query
   ```
   EnemrableProject
      EnumerableSort
        EnumerableFilter
          ...
   ```
   
   Though the plan above makes sense, but I think we want to see a generated 
plan that indeed have Sort enforced. Thus this test is updated.
   




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to