maropu commented on a change in pull request #29677:
URL: https://github.com/apache/spark/pull/29677#discussion_r496650338



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala
##########
@@ -52,7 +52,10 @@ case class EnsureRequirements(conf: SQLConf) extends 
Rule[SparkPlan] {
       case (child, distribution) =>
         val numPartitions = distribution.requiredNumPartitions
           .getOrElse(conf.numShufflePartitions)
-        ShuffleExchangeExec(distribution.createPartitioning(numPartitions), 
child)
+        // Like optimizer.CollapseRepartition removes adjacent repartition 
operations,
+        // adjacent repartitions performed by shuffle can be also removed.
+        val newChild = if (child.isInstanceOf[ShuffleExchangeExec]) 
child.children.head else child

Review comment:
       > Do you mean we should check whether outputPartitioning of 
ShuffleExchangeExec to be inserted and the one of the existing 
ShuffleExchangeExec?
   
   I didn't mean so; have you checked #26946? This PR currently removes 
shuffles incrrectly;
   ```
   scala> spark.range(1).selectExpr("id as a").write.saveAsTable("test")
   scala> sql("SELECT /*+ REPARTITION(5) */ * FROM test ORDER BY a").explain()
   == Physical Plan ==
   *(2) Sort [a#5L ASC NULLS FIRST], true, 0
   +- Exchange rangepartitioning(a#5L ASC NULLS FIRST, 200), true, [id=#53]
      +- Exchange RoundRobinPartitioning(5), false, [id=#52] <--- !!! Removed? 
!!!
         +- *(1) ColumnarToRow
            +- FileScan parquet default.test[a#5L] Batched: true, DataFilters: 
[], Format: Parquet, Location: 
InMemoryFileIndex[file:/Users/maropu/Repositories/spark/spark-master/spark-warehouse/test],
 PartitionFilters: [], PushedFilters: [], ReadSchema: struct<a:bigint>
   ```




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

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