@@ -20,6 +20,7 @@ package org.apache.spark.util.collection
20
20
import java .io .{InputStream , BufferedInputStream , FileInputStream , File , Serializable , EOFException }
21
21
import java .util .Comparator
22
22
23
+ import scala .collection .BufferedIterator
23
24
import scala .collection .mutable
24
25
import scala .collection .mutable .ArrayBuffer
25
26
@@ -231,7 +232,7 @@ class ExternalAppendOnlyMap[K, V, C](
231
232
// Input streams are derived both from the in-memory map and spilled maps on disk
232
233
// The in-memory map is sorted in place, while the spilled maps are already in sorted order
233
234
private val sortedMap = currentMap.destructiveSortedIterator(comparator)
234
- private val inputStreams = Seq (sortedMap) ++ spilledMaps
235
+ private val inputStreams = ( Seq (sortedMap) ++ spilledMaps).map(it => it.buffered)
235
236
236
237
inputStreams.foreach { it =>
237
238
val kcPairs = getMorePairs(it)
@@ -246,13 +247,13 @@ class ExternalAppendOnlyMap[K, V, C](
246
247
* In the event of key hash collisions, this ensures no pairs are hidden from being merged.
247
248
* Assume the given iterator is in sorted order.
248
249
*/
249
- private def getMorePairs (it : Iterator [(K , C )]): ArrayBuffer [(K , C )] = {
250
+ private def getMorePairs (it : BufferedIterator [(K , C )]): ArrayBuffer [(K , C )] = {
250
251
val kcPairs = new ArrayBuffer [(K , C )]
251
252
if (it.hasNext) {
252
253
var kc = it.next()
253
254
kcPairs += kc
254
255
val minHash = kc._1.hashCode()
255
- while (it.hasNext && kc ._1.hashCode() == minHash) {
256
+ while (it.hasNext && it.head ._1.hashCode() == minHash) {
256
257
kc = it.next()
257
258
kcPairs += kc
258
259
}
@@ -325,7 +326,8 @@ class ExternalAppendOnlyMap[K, V, C](
325
326
*
326
327
* StreamBuffers are ordered by the minimum key hash found across all of their own pairs.
327
328
*/
328
- private case class StreamBuffer (iterator : Iterator [(K , C )], pairs : ArrayBuffer [(K , C )])
329
+ private class StreamBuffer (
330
+ val iterator : BufferedIterator [(K , C )], val pairs : ArrayBuffer [(K , C )])
329
331
extends Comparable [StreamBuffer ] {
330
332
331
333
def isEmpty = pairs.length == 0
0 commit comments