Jess> Is my test incorrect? This also fails: The test looks like a correct one, however its correctness depends on the implementation of runDuplicateSortCheck. It turns out the implementation was wrong, so the top-level sort was removed not by SortRemoveRule, but it was removed by a mere fact that the test dd ask Planner to produce a result with empty collation.
I've fixed that in https://issues.apache.org/jira/browse/CALCITE-2768, and I've added your test there, so top-level order by is not removed: https://gitbox.apache.org/repos/asf?p=calcite.git;a=commitdiff;h=b54f6de9d7f87e9853fc9ec01b586555a089b913 Vladimir
