JkSelf commented on a change in pull request #26434: [SPARK-29544] [SQL]
optimize skewed partition based on data size
URL: https://github.com/apache/spark/pull/26434#discussion_r358583953
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/ReduceNumShufflePartitions.scala
##########
@@ -145,39 +156,36 @@ case class ReduceNumShufflePartitions(conf: SQLConf)
extends Rule[SparkPlan] {
distinctNumPreShufflePartitions.length == 1,
"There should be only one distinct value of the number pre-shuffle
partitions " +
"among registered Exchange operator.")
- val numPreShufflePartitions = distinctNumPreShufflePartitions.head
val partitionStartIndices = ArrayBuffer[Int]()
- // The first element of partitionStartIndices is always 0.
- partitionStartIndices += 0
-
- var postShuffleInputSize = 0L
-
- var i = 0
- while (i < numPreShufflePartitions) {
- // We calculate the total size of ith pre-shuffle partitions from all
pre-shuffle stages.
- // Then, we add the total size to postShuffleInputSize.
- var nextShuffleInputSize = 0L
- var j = 0
- while (j < mapOutputStatistics.length) {
- nextShuffleInputSize += mapOutputStatistics(j).bytesByPartitionId(i)
- j += 1
- }
-
- // If including the nextShuffleInputSize would exceed the target
partition size, then start a
- // new partition.
- if (i > 0 && postShuffleInputSize + nextShuffleInputSize >
targetPostShuffleInputSize) {
- partitionStartIndices += i
- // reset postShuffleInputSize.
- postShuffleInputSize = nextShuffleInputSize
- } else {
- postShuffleInputSize += nextShuffleInputSize
- }
-
- i += 1
+ val partitionEndIndices = ArrayBuffer[Int]()
+ val numPartitions = mapOutputStatistics.map(stats =>
stats.bytesByPartitionId.length).head
+ val includedPartitions = (0 until
numPartitions).filter(!excludedPartitions.contains(_))
+ val firstStartIndex = includedPartitions(0)
+ partitionStartIndices += firstStartIndex
+ var postShuffleInputSize =
mapOutputStatistics.map(_.bytesByPartitionId(firstStartIndex)).sum
+ var i = firstStartIndex
+ includedPartitions.filter(_ != firstStartIndex).foreach {
+ nextPartitionIndices =>
+ var nextShuffleInputSize =
+
mapOutputStatistics.map(_.bytesByPartitionId(nextPartitionIndices)).sum
+ // If nextPartitionIndices is skewed and omitted, or including
+ // the nextShuffleInputSize would exceed the target partition size,
+ // then start a new partition.
+ if (nextPartitionIndices != i + 1 ||
Review comment:
The `nextPartitionIndices ` is excluded.
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]