Scala map smoothing in RDD

I have an RDD that looks like this:

uidProcessedKeywords: org.apache.spark.rdd.RDD[(Long, Map[String,Double])]


How to flatten the map in RDD to get this:

org.apache.spark.rdd.RDD[(Long, String, Double)]



source to share

1 answer

val x = sc.parallelize(List((2, Map("a" -> 0.2, "b" -> 0.3))))
x.flatMap { 
    case (id, m) => { case (k, v) => (id, k, v)}
res1: Array[(Int, String, Double)] = Array((2,a,0.2), (2,b,0.3))




All Articles