cloud-fan commented on code in PR #37250:
URL: https://github.com/apache/spark/pull/37250#discussion_r927779233
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -1528,28 +1528,44 @@ object EliminateSorts extends Rule[LogicalPlan] {
}
case Sort(orders, false, child) if
SortOrder.orderingSatisfies(child.outputOrdering, orders) =>
applyLocally.lift(child).getOrElse(child)
- case s @ Sort(_, _, child) => s.copy(child = recursiveRemoveSort(child))
+ case s @ Sort(_, global, child) => s.copy(child =
recursiveRemoveSort(child, global))
case j @ Join(originLeft, originRight, _, cond, _) if
cond.forall(_.deterministic) =>
- j.copy(left = recursiveRemoveSort(originLeft), right =
recursiveRemoveSort(originRight))
+ j.copy(left = recursiveRemoveSort(originLeft, true),
+ right = recursiveRemoveSort(originRight, true))
case g @ Aggregate(_, aggs, originChild) if isOrderIrrelevantAggs(aggs) =>
- g.copy(child = recursiveRemoveSort(originChild))
+ g.copy(child = recursiveRemoveSort(originChild, true))
}
- private def recursiveRemoveSort(plan: LogicalPlan): LogicalPlan = {
+ /**
+ * If the upper sort is global then we can remove the global or local sort
recursively.
+ * If the upper sort is local then we can only remove the local sort
recursively.
+ */
+ private def recursiveRemoveSort(
+ plan: LogicalPlan,
+ canRemoveGlobalSort: Boolean): LogicalPlan = {
if (!plan.containsPattern(SORT)) {
return plan
}
plan match {
- case Sort(_, _, child) => recursiveRemoveSort(child)
+ case Sort(_, _, child) if canRemoveGlobalSort =>
Review Comment:
nit:
```
case Sort(_, global, child) if canRemoveGlobalSort || !global =>
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]