-
Notifications
You must be signed in to change notification settings - Fork 4
/
RDDSerializationTest.scala
64 lines (58 loc) · 1.65 KB
/
RDDSerializationTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.hammerlab.spark.test.rdd
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream }
import org.apache.hadoop.io.{ BytesWritable, NullWritable }
import org.apache.hadoop.mapred.SequenceFileOutputFormat
import org.apache.spark.rdd.RDD
import org.hammerlab.hadoop.splits.UnsplittableSequenceFileInputFormat
import org.hammerlab.paths.Path
import scala.reflect.ClassTag
class RDDSerializationTest
extends RDDSerialization {
override protected def serializeRDD[T: ClassTag](rdd: RDD[T],
path: Path): RDD[T] = {
rdd
.map {
t ⇒
NullWritable.get → {
val bos = new ByteArrayOutputStream()
val oos = new ObjectOutputStream(bos)
oos.writeObject(t)
oos.close()
new BytesWritable(bos.toByteArray)
}
}
.saveAsHadoopFile[
SequenceFileOutputFormat[
NullWritable,
BytesWritable
]
](
path.toString
)
rdd
}
override protected def deserializeRDD[T: ClassTag](path: Path): RDD[T] =
sc
.hadoopFile[
NullWritable,
BytesWritable,
UnsplittableSequenceFileInputFormat[
NullWritable,
BytesWritable
]
](
path.toString
)
.values
.map {
bytes ⇒
val bis = new ByteArrayInputStream(bytes.getBytes)
val ois = new ObjectInputStream(bis)
val t = ois.readObject().asInstanceOf[T]
ois.close()
t
}
test("ints round trip") {
verifyFileSizesAndSerde(1 to 1000, 23565)
}
}