Github user kanzhang commented on a diff in the pull request:
https://github.com/apache/spark/pull/776#discussion_r13269104
--- 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 current implementation would lose elements for all types of
numeric ranges (including Long and Double) when we zip a numeric range with
other sequences, because we partition numeric ranges differently from other
sequences. This patch fixes it by partitioning numeric ranges at exactly the
same indexes as we would on other sequences. However, we still depend on
```take``` and ```drop``` being implemented correctly on numeric ranges for
things to work. The Scala bug affects ```take``` and ```drop``` on Double
ranges, but not on other numeric ranges like Long (hence, the unit tests in
this patch, which is based on Long ranges, work).
---
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.
---