Reputation: 21
I need to convert rdd into hashMap. I am having data in RDD like below:
(FRUIT, List(Apple,Banana,Mango)) (VEGETABLE, List(Potato,Tomato))
I am having below code currently
object JsonParse {
def main(args: Array[String]){
val sc = new SparkContext(new SparkConf().setAppName("JsonParse").setMaster("local"))
val arr = Array(("FRUIT",List("Apple","Banana","Mango")),("VEGETABLE", List("Potato","Tomato")))
val Rdd = sc.parallelize(arr)
how to proceed further??
Upvotes: 2
Views: 3123
Reputation: 4471
rdd.collectAsMap() // Map(VEGETABLE -> List(Potato, Tomato), FRUIT -> List(Apple, Banana, Mango))
Upvotes: 4
Reputation: 1291
Try
rdd.collect.toMap
to convert it to a Map
. Action collect
gathers the contents of the rdd
locally to the master node.
Upvotes: 1