You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/07/23 04:48:15 UTC
[GitHub] [spark] ulysses-you commented on a diff in pull request #37250: [SPARK-39835][SQL] Fix EliminateSorts remove global sort below the local sort
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org