ulysses-you commented on code in PR #37250:
URL: https://github.com/apache/spark/pull/37250#discussion_r928077499
##########
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.
Review Comment:
The semantics of global + local sort should be range partition + local sort,
so we can not remove the global sort which is under local sort as we can not
remove range partition directly. BTW, I will add a new rule to optimzie this
pattern after fix this pr.
--
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]