Skip to content

Commit e48f018

Browse files
committed
[SPARK-1837] code refactoring
1 parent 67c33b5 commit e48f018

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

core/src/main/scala/org/apache/spark/rdd/ParallelCollectionRDD.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ private object ParallelCollectionRDD {
117117
if (numSlices < 1) {
118118
throw new IllegalArgumentException("Positive number of slices required")
119119
}
120-
// Sequences need to be sliced at same positions for operations
120+
// Sequences need to be sliced at the same set of index positions for operations
121121
// like RDD.zip() to behave as expected
122-
def positions(length: Long, numSlices: Int) = {
123-
(0 until numSlices).map(i => {
122+
def positions(length: Long, numSlices: Int): Iterator[(Int, Int)] = {
123+
(0 until numSlices).iterator.map(i => {
124124
val start = ((i * length) / numSlices).toInt
125125
val end = (((i + 1) * length) / numSlices).toInt
126126
(start, end)
@@ -140,7 +140,7 @@ private object ParallelCollectionRDD {
140140
positions(r.length, numSlices).map({
141141
case (start, end) =>
142142
new Range(r.start + start * r.step, r.start + end * r.step, r.step)
143-
}).asInstanceOf[Seq[Seq[T]]]
143+
}).toSeq.asInstanceOf[Seq[Seq[T]]]
144144
}
145145
case nr: NumericRange[_] => {
146146
// For ranges of Long, Double, BigInteger, etc
@@ -158,7 +158,7 @@ private object ParallelCollectionRDD {
158158
positions(array.length, numSlices).map({
159159
case (start, end) =>
160160
array.slice(start, end).toSeq
161-
})
161+
}).toSeq
162162
}
163163
}
164164
}

core/src/test/scala/org/apache/spark/rdd/ParallelCollectionSplitSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ParallelCollectionSplitSuite extends FunSuite with Checkers {
121121
}
122122

123123
test("identical slice sizes between List and NumericRange") {
124-
val r = ParallelCollectionRDD.slice(List(1,2), 4)
124+
val r = ParallelCollectionRDD.slice(List(1, 2), 4)
125125
val nr = ParallelCollectionRDD.slice(1L to 2L, 4)
126126
assert(r.size === 4)
127127
for (i <- 0 until r.size) {

0 commit comments

Comments
 (0)