Skip to content

Commit 923dba5

Browse files
xoltarmateiz
authored andcommitted
Added a unit test for PairRDDFunctions.lookup
Lookup didn't have a unit test. Added two tests, one for with a partitioner, and one for without. Author: Bryn Keller <[email protected]> Closes #36 from xoltar/lookup and squashes the following commits: 3bc0d44 [Bryn Keller] Added a unit test for PairRDDFunctions.lookup
1 parent b55cade commit 923dba5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,32 @@ class PairRDDFunctionsSuite extends FunSuite with SharedSparkContext {
347347
*/
348348
pairs.saveAsNewAPIHadoopFile[ConfigTestFormat]("ignored")
349349
}
350+
351+
test("lookup") {
352+
val pairs = sc.parallelize(Array((1,2), (3,4), (5,6), (5,7)))
353+
354+
assert(pairs.partitioner === None)
355+
assert(pairs.lookup(1) === Seq(2))
356+
assert(pairs.lookup(5) === Seq(6,7))
357+
assert(pairs.lookup(-1) === Seq())
358+
359+
}
360+
361+
test("lookup with partitioner") {
362+
val pairs = sc.parallelize(Array((1,2), (3,4), (5,6), (5,7)))
363+
364+
val p = new Partitioner {
365+
def numPartitions: Int = 2
366+
367+
def getPartition(key: Any): Int = Math.abs(key.hashCode() % 2)
368+
}
369+
val shuffled = pairs.partitionBy(p)
370+
371+
assert(shuffled.partitioner === Some(p))
372+
assert(shuffled.lookup(1) === Seq(2))
373+
assert(shuffled.lookup(5) === Seq(6,7))
374+
assert(shuffled.lookup(-1) === Seq())
375+
}
350376
}
351377

352378
/*

0 commit comments

Comments
 (0)