国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

spark_API-collectAsMap

2019-11-14 11:18:04
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

collectAsMap()

返回hashMap包含所有RDD中的分片,key如果重復(fù),后邊的元素會(huì)覆蓋前面的元素。/**  * Return the key-value pairs in this RDD to the master as a Map.  *  * Warning: this doesn't return a multimap (so if you have multiple values to the same key, only  *          one value per key is PReserved in the map returned)  *  * @note this method should only be used if the resulting data is expected to be small, as  * all the data is loaded into the driver's memory.  */def collectAsMap(): Map[K, V] = self.withScope {  val data = self.collect()  val map = new mutable.HashMap[K, V]  map.sizeHint(data.length)  data.foreach { pair => map.put(pair._1, pair._2) }  map}
package com.dt.spark.main.RDDLearn.RDDCollectAsMapimport org.apache.spark.{SparkContext, SparkConf}/**  * Created by hjw on 17/2/4.  *//*collect (較常用)將RDD中的數(shù)據(jù)收集起來(lái),變成一個(gè)Array,僅限數(shù)據(jù)量比較小的時(shí)候。collectAsMap()返回hashMap包含所有RDD中的分片,key如果重復(fù),后邊的元素會(huì)覆蓋前面的元素。/**   * Return the key-value pairs in this RDD to the master as a Map.   *   * Warning: this doesn't return a multimap (so if you have multiple values to the same key, only   *          one value per key is preserved in the map returned)   *   * @note this method should only be used if the resulting data is expected to be small, as   * all the data is loaded into the driver's memory.   */  def collectAsMap(): Map[K, V] = self.withScope {    val data = self.collect()    val map = new mutable.HashMap[K, V]    map.sizeHint(data.length)    data.foreach { pair => map.put(pair._1, pair._2) }    map  } */object RDDCollectAsMapTest {  def main(args: Array[String]) {    val conf = new SparkConf()    conf.setAppName("test")    conf.setMaster("local")    val sc = new SparkContext(conf)    val rdd = sc.parallelize(List((1, "a"), (1, "b"), (1, "c"), (2, "d"), (2, "e"), (3, "g")) )    val rddMap = rdd.collectAsMap()    rddMap.foreach(println(_))//    (2,e)//    (1,c)//    (3,g)  }}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 利津县| 呼和浩特市| 湖州市| 沁源县| 北安市| 和田县| 民权县| 景洪市| 崇信县| 台北市| 方山县| 绥化市| 奇台县| 迭部县| 甘孜县| 鹿邑县| 鄂托克旗| 南皮县| 萨迦县| 社旗县| 金溪县| 石嘴山市| 夹江县| 揭阳市| 望江县| 松潘县| 莱西市| 瑞昌市| 凤凰县| 南宁市| 嵊泗县| 依兰县| 台北县| 怀化市| 扬中市| 固阳县| 遂川县| 鹤岗市| 平定县| 清苑县| 迁西县|