ulysses-you commented on code in PR #43841:
URL: https://github.com/apache/spark/pull/43841#discussion_r1396615662


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala:
##########
@@ -68,7 +68,13 @@ case class EnsureRequirements(
       case (child, distribution) =>
         val numPartitions = distribution.requiredNumPartitions
           .getOrElse(conf.numShufflePartitions)
-        ShuffleExchangeExec(distribution.createPartitioning(numPartitions), 
child, shuffleOrigin)
+        // Avoid generating redundant ShuffleExchangeExec node
+        val shuffleChild = child match {
+          case s: ShuffleExchangeExec => s.child
+          case other => other
+        }
+        ShuffleExchangeExec(
+          distribution.createPartitioning(numPartitions), shuffleChild, 
shuffleOrigin)

Review Comment:
   My point is that, it's a user-specified shuffle, we can not just remove it. 
Does it affect shuffle reuse ? e.g.,
   
   ```
   with t (select /*+ repartition */ * from t)
   select * from t join t2
   union all
   select * from t
   ```
   



-- 
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]

Reply via email to