Github user kanzhang commented on a diff in the pull request:
https://github.com/apache/spark/pull/776#discussion_r13241563
--- Diff:
core/src/main/scala/org/apache/spark/rdd/ParallelCollectionRDD.scala ---
@@ -128,18 +137,17 @@ private object ParallelCollectionRDD {
r.start, r.end + sign, r.step).asInstanceOf[Seq[T]], numSlices)
}
case r: Range => {
- (0 until numSlices).map(i => {
- val start = ((i * r.length.toLong) / numSlices).toInt
- val end = (((i + 1) * r.length.toLong) / numSlices).toInt
- new Range(r.start + start * r.step, r.start + end * r.step,
r.step)
+ positions(r.length, numSlices).map({
+ case (start, end) =>
+ new Range(r.start + start * r.step, r.start + end * r.step,
r.step)
}).asInstanceOf[Seq[Seq[T]]]
}
case nr: NumericRange[_] => {
// For ranges of Long, Double, BigInteger, etc
val slices = new ArrayBuffer[Seq[T]](numSlices)
- val sliceSize = (nr.size + numSlices - 1) / numSlices // Round up
to catch everything
var r = nr
- for (i <- 0 until numSlices) {
+ for ((start, end) <- positions(nr.length, numSlices)) {
+ val sliceSize = end - start
slices += r.take(sliceSize).asInstanceOf[Seq[T]]
--- End diff --
@mateiz the use case wasn't mine, it was from reporter of SPARK-1817. Btw,
I think this PR can be committed independent of Scala fix. It fixes the issue
for other numeric ranges (e.g., Long), and will also work on Double once the
Scala fix is in.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---