GitHub user JoshRosen opened a pull request: https://github.com/apache/spark/pull/9140
[SPARK-11135] [SQL] Exchange incorrectly skips sorts when existing ordering is non-empty subset of required ordering In Spark SQL, the Exchange planner tries to avoid unnecessary sorts in cases where the data has already been sorted by a superset of the requested sorting columns. For instance, let's say that a query calls for an operator's input to be sorted by `a.asc` and the input happens to already be sorted by `[a.asc, b.asc]`. In this case, we do not need to re-sort the input. The converse, however, is not true: if the query calls for `[a.asc, b.asc]`, then `a.asc` alone will not satisfy the ordering requirements, requiring an additional sort to be planned by Exchange. However, the current Exchange code gets this wrong and incorrectly skips sorting when the existing output ordering is a subset of the required ordering. This is simple to fix, however. This bug was introduced in https://github.com/apache/spark/pull/7458, so it affects 1.5.0+. This patch fixes the bug and significantly improves the unit test coverage of Exchange's sort-planning logic. You can merge this pull request into a Git repository by running: $ git pull https://github.com/JoshRosen/spark SPARK-11135 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/9140.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #9140 ---- commit 5c022adad06124bd491180175a59bec34750a909 Author: Josh Rosen <joshro...@databricks.com> Date: 2015-10-15T22:06:07Z Add assertions to guard against zip bugs. commit 82a73c0a6634b6b903f479809b3a5d9ef51a82fd Author: Josh Rosen <joshro...@databricks.com> Date: 2015-10-15T22:16:43Z Add regression tests in PlannerSuite. commit a505a9df3ba152c8052dae0e53b4cbc18dbfe3a0 Author: Josh Rosen <joshro...@databricks.com> Date: 2015-10-15T22:17:26Z Fix bug ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org