美文网首页
countByKey()

countByKey()

作者: yayooo | 来源:发表于2019-08-06 20:18 被阅读0次

    key出现的次数

    package com.atguigu
    
    import org.apache.spark.rdd.RDD
    import org.apache.spark.{SparkConf, SparkContext}
    
    object Action {
      def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("ADCount")
    
        val sc = new SparkContext(conf)
    
        val rdd: RDD[(String, Int)] = sc.makeRDD(List(("a",1),("b",2),("a",3),("b",4),("a",5)))
        val stringToLong: collection.Map[String, Long] = rdd.countByKey()
        println(stringToLong)
    
      }
    }
    
    

    Map(a -> 3, b -> 2)

    相关文章

      网友评论

          本文标题:countByKey()

          本文链接:https://www.haomeiwen.com/subject/mfttdctx.html