viirya commented on code in PR #44429:
URL: https://github.com/apache/spark/pull/44429#discussion_r1433407429
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -1602,12 +1595,6 @@ object EliminateSorts extends Rule[LogicalPlan] {
plan match {
case Sort(_, global, child) if canRemoveGlobalSort || !global =>
recursiveRemoveSort(child, canRemoveGlobalSort)
- case Sort(sortOrder, true, child) =>
- // For this case, the upper sort is local so the ordering of present
sort is unnecessary,
- // so here we only preserve its output partitioning using
`RepartitionByExpression`.
- // We should use `None` as the optNumPartitions so AQE can coalesce
shuffle partitions.
- // This behavior is same with original global sort.
- RepartitionByExpression(sortOrder, recursiveRemoveSort(child, true),
None)
Review Comment:
Said there are Sorts like
```
- Sort (local)
- Sort (global)
- Sort (local)
```
We reach:
```scala
case s @ Sort(_, global, child) => s.copy(child = recursiveRemoveSort(child,
global))
```
Previously we can get rid of the middle global Sort and the bottom local
Sort by `RepartitionByExpression(sortOrder, recursiveRemoveSort(child, true),
None)` and:
```scala
case Sort(_, global, child) if canRemoveGlobalSort || !global =>
recursiveRemoveSort(child, canRemoveGlobalSort)
```
How does `EliminateSorts` still do it?
The code you point is same (not changed in this PR):
```scala
case s @ Sort(_, global, child) => s.copy(child = recursiveRemoveSort(child,
global))
```
But in `recursiveRemoveSort`, as `canRemoveGlobalSort` is false, we don't
get rid of the middle global Sort now (it will be done in
`RemoveRedundantSorts` now).
Do I miss ore misread something?
--
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]