Reputation: 173
How to find the first element in a normal RDD( Because in PairRDD, we can use lookup(key) API ) which satisfy a predicate? And after finding the first element, it should exit the RDD traversal. Looking for a solution without using legacy for loops.
Upvotes: 2
Views: 10352
Reputation: 2799
The above solutions stated are perfectly correct. Here is another method to achieve the same goal
rdd.filter(p).first
Upvotes: 1
Reputation: 7564
How about
rdd.filter(p).top(1)
or if you don't have an order on the RDD
rdd.filter(p).take(1)
Upvotes: 7