southernriver closed pull request #23478: [SPARK-26543][SQL] Support the coordinator to determine post-shuffle partitions more reasonably URL: https://github.com/apache/spark/pull/23478
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/ExchangeCoordinator.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/ExchangeCoordinator.scala index 78f11ca8d8c78..59418c4fbd81f 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/ExchangeCoordinator.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/ExchangeCoordinator.scala @@ -177,11 +177,17 @@ class ExchangeCoordinator( // If including the nextShuffleInputSize would exceed the target partition size, then start a // new partition. if (i > 0 && postShuffleInputSize + nextShuffleInputSize > targetPostShuffleInputSize) { - partitionStartIndices += i + if (postShuffleInputSize != 0) { + partitionStartIndices += i + } // reset postShuffleInputSize. postShuffleInputSize = nextShuffleInputSize } else postShuffleInputSize += nextShuffleInputSize + // filter the last indice which will split the postShuffleInputSize=0 + if (postShuffleInputSize == 0 && i == numPreShufflePartitions - 1) { + partitionStartIndices.remove(partitionStartIndices.size - 1) + } i += 1 } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/ExchangeCoordinatorSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/ExchangeCoordinatorSuite.scala index 737eeb0af586e..2f9fd870cf56f 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/ExchangeCoordinatorSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/ExchangeCoordinatorSuite.scala @@ -63,7 +63,7 @@ class ExchangeCoordinatorSuite extends SparkFunSuite with BeforeAndAfterAll { { // All bytes per partition are 0. val bytesByPartitionId = Array[Long](0, 0, 0, 0, 0) - val expectedPartitionStartIndices = Array[Int](0) + val expectedPartitionStartIndices = Array[Int]() checkEstimation(coordinator, Array(bytesByPartitionId), expectedPartitionStartIndices) } @@ -85,7 +85,14 @@ class ExchangeCoordinatorSuite extends SparkFunSuite with BeforeAndAfterAll { { // There are a few large pre-shuffle partitions. val bytesByPartitionId = Array[Long](110, 10, 100, 110, 0) - val expectedPartitionStartIndices = Array[Int](0, 1, 2, 3, 4) + val expectedPartitionStartIndices = Array[Int](0, 1, 2, 3) + checkEstimation(coordinator, Array(bytesByPartitionId), expectedPartitionStartIndices) + } + + { + // There are a few large pre-shuffle partitions and some bytes per partition are 0. + val bytesByPartitionId = Array[Long](110, 120, 0, 130, 0, 0, 100, 110, 0) + val expectedPartitionStartIndices = Array[Int](0, 1, 2, 4, 7) checkEstimation(coordinator, Array(bytesByPartitionId), expectedPartitionStartIndices) } @@ -123,7 +130,7 @@ class ExchangeCoordinatorSuite extends SparkFunSuite with BeforeAndAfterAll { // All bytes per partition are 0. val bytesByPartitionId1 = Array[Long](0, 0, 0, 0, 0) val bytesByPartitionId2 = Array[Long](0, 0, 0, 0, 0) - val expectedPartitionStartIndices = Array[Int](0) + val expectedPartitionStartIndices = Array[Int]() checkEstimation( coordinator, Array(bytesByPartitionId1, bytesByPartitionId2), @@ -206,7 +213,7 @@ class ExchangeCoordinatorSuite extends SparkFunSuite with BeforeAndAfterAll { // the size of data is 0. val bytesByPartitionId1 = Array[Long](0, 0, 0, 0, 0) val bytesByPartitionId2 = Array[Long](0, 0, 0, 0, 0) - val expectedPartitionStartIndices = Array[Int](0) + val expectedPartitionStartIndices = Array[Int]() checkEstimation( coordinator, Array(bytesByPartitionId1, bytesByPartitionId2), ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org