Reputation: 173
I have a JavaPairRDD named 'pair' and want to count the number of times a key occurs (I think the JavaPairRDD is not like a HashMap and will have keys repeated, am I right ?). The countByKey function returns an Object, instead of a Long. So Doesn't it return the count ? Or what is the Object returned, and can we find the count from it ?
Upvotes: 0
Views: 1392
Reputation: 13154
JavaPairRDD.countByKey()
returns a Map
and the values are in fact the counts. Java has a bit of trouble with type inference in Spark (it's much, much better in Scala!), so you need to explicitly cast the values from Object
to Long
.
Upvotes: 1