Skip to content
Snippets Groups Projects
Commit 903f3518 authored by Mark Hamstra's avatar Mark Hamstra
Browse files

fall back to filter-map-collect when calling lookup() on an RDD without a partitioner

parent b575cbe0
No related branches found
No related tags found
No related merge requests found
......@@ -438,7 +438,7 @@ class PairRDDFunctions[K: ClassManifest, V: ClassManifest](
val res = self.context.runJob(self, process _, Array(index), false)
res(0)
case None =>
throw new UnsupportedOperationException("lookup() called on an RDD without a partitioner")
self.filter(_._1 == key).map(_._2).collect
}
}
......
......@@ -130,6 +130,17 @@ public class JavaAPISuite implements Serializable {
Assert.assertEquals(2, foreachCalls);
}
@Test
public void lookup() {
JavaPairRDD<String, String> categories = sc.parallelizePairs(Arrays.asList(
new Tuple2<String, String>("Apples", "Fruit"),
new Tuple2<String, String>("Oranges", "Fruit"),
new Tuple2<String, String>("Oranges", "Citrus")
));
Assert.assertEquals(2, categories.lookup("Oranges").size());
Assert.assertEquals(2, categories.groupByKey().lookup("Oranges").get(0).size());
}
@Test
public void groupBy() {
JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 1, 2, 3, 5, 8, 13));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment