[SPARK-17271] [SQL] Planner adds un-necessary Sort even if child orde… #14920
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Ports #14841 and #14910 from
master
tobranch-2.0
Jira : https://issues.apache.org/jira/browse/SPARK-17271
Planner is adding un-needed SORT operation due to bug in the way comparison for
SortOrder
is done at https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala#L253SortOrder
needs to be compared semantically becauseExpression
within twoSortOrder
can be "semantically equal" but not literally equal objects.eg. In case of
sql("SELECT * FROM table1 a JOIN table2 b ON a.col1=b.col1")
Expression in required SortOrder:
Expression in child SortOrder:
Notice that the output column has a qualifier but the child attribute does not but the inherent expression is the same and hence in this case we can say that the child satisfies the required sort order.
This PR includes following changes:
semanticEquals
method toSortOrder
so that it can compare underlying child expressions semantically (and not using default Object.equals)EnsureRequirements
to use semantic comparison of SortOrderHow was this patch tested?
PlannerSuite
. Ran rest tests inPlannerSuite