为什么我得到a"构造函数无法实例化为期望的类型"错误?

时间:2015-12-13 09:00:07

标签: scala apache-spark scala-collections

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,我该怎么办?谢谢!

1 个答案:

答案 0 :(得分:3)

provinces_cookies是包含地图的RDD,因此您应首先迭代RDD然后迭代Map:

 provinces_cookies.foreach ( hmap =>
    for((k,v) <- hmap) println (k + "-->" + v)
 )