Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a unit test for PairRDDFunctions.lookup

  • Loading branch information...
commit 3bc0d44a9aaf23c996f840dd26792cff341b828b 1 parent c86eec5
Bryn Keller authored
View
26 core/src/test/scala/org/apache/spark/rdd/PairRDDFunctionsSuite.scala
@@ -347,6 +347,32 @@ class PairRDDFunctionsSuite extends FunSuite with SharedSparkContext {
*/
pairs.saveAsNewAPIHadoopFile[ConfigTestFormat]("ignored")
}
+
+ test("lookup") {
+ val pairs = sc.parallelize(Array((1,2), (3,4), (5,6), (5,7)))
+
+ assert(pairs.partitioner === None)
+ assert(pairs.lookup(1) === Seq(2))
+ assert(pairs.lookup(5) === Seq(6,7))
+ assert(pairs.lookup(-1) === Seq())
+
+ }
+
+ test("lookup with partitioner") {
+ val pairs = sc.parallelize(Array((1,2), (3,4), (5,6), (5,7)))
+
+ val p = new Partitioner {
+ def numPartitions: Int = 2
+
+ def getPartition(key: Any): Int = Math.abs(key.hashCode() % 2)
+ }
+ val shuffled = pairs.partitionBy(p)
+
+ assert(shuffled.partitioner === Some(p))
+ assert(shuffled.lookup(1) === Seq(2))
+ assert(shuffled.lookup(5) === Seq(6,7))
+ assert(shuffled.lookup(-1) === Seq())
+ }
}
/*
Please sign in to comment.
Something went wrong with that request. Please try again.