Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19763#discussion_r152022126
--- Diff: core/src/main/scala/org/apache/spark/MapOutputTracker.scala ---
@@ -472,16 +475,45 @@ private[spark] class MapOutputTrackerMaster(
shuffleStatuses.get(shuffleId).map(_.findMissingPartitions())
}
+ /**
+ * Try to equally divide Range(0, num) to divisor slices
+ */
+ def equallyDivide(num: Int, divisor: Int): Iterator[Seq[Int]] = {
+ assert(divisor > 0, "Divisor should be positive")
+ val (each, remain) = (num / divisor, num % divisor)
+ val (smaller, bigger) = (0 until num).splitAt((divisor-remain) * each)
--- End diff --
my proposal
```
def equallyDivide(numElements: Int, numBuckets: Int) {
val elementsPerBucket = numElements / numBuckets
val remaining = numElements % numBuckets
if (remaining == 0) {
0.until(num).grouped(elementsPerBucket)
} else {
val splitPoint = (elementsPerBucket + 1) * remaining
0.to(splitPoint).grouped(elementsPerBucket + 1) ++ (splitPoint +
1).until(numElements).grouped(elementsPerBucket)
}
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]