在spark-shell
下,经过一些计算后,我得到了HashMap
类型的值,但我无法列出所有(key, value)
:
scala> provinces_cookies
res44: org.apache.spark.rdd.RDD[scala.collection.mutable.HashMap[Int,Int]] = MapPartitionsRDD[20] at map at <console>:44
scala> for( (k, v) <- provinces_cookies) println ( k + "-->" + v)
<console>:47: error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: scala.collection.mutable.HashMap[Int,Int]
for( (k, v) <- provinces_cookies) println ( k + "-->" + v)
要列出所有key --> value
,我该怎么办?谢谢!
答案 0 :(得分:3)
provinces_cookies是包含地图的RDD,因此您应首先迭代RDD然后迭代Map:
provinces_cookies.foreach ( hmap =>
for((k,v) <- hmap) println (k + "-->" + v)
)