首页 > 其他 > 详细

Mr、Hive、Spark实现wordCount

时间:2020-10-05 14:13:26      阅读:47      评论:0      收藏:0      [点我收藏+]

Hive: https://www.cnblogs.com/Coeus-P/p/13356392.html

Spark:

def main(args: Array[String]): Unit = {
    //println("Hello, WordCount")
    val conf = new SparkConf()
    conf.setAppName("wordCount")
    conf.setMaster("local")

    val sc = new SparkContext(conf)
    //A B
    val lines: RDD[String] = sc.textFile("./data/words")
    //A
    //B
    val words: RDD[String] = lines.flatMap(lines => {
      lines.split(" ")
    })
    //A 1
    //B 1
    val pairWords: RDD[(String, Int)] = words.map(words=>{new Tuple2(words, 1)})
    //A 1
    //B 2
    val result:RDD[(String, Int)] = pairWords.reduceByKey((v1:Int, v2:Int)=>{v1+v2})
    val result1 = result.sortBy(tp=>{tp._2})
    result1.foreach(one=>{
      println(one)
    })
    sc.stop()
  }

Mr、Hive、Spark实现wordCount

原文:https://www.cnblogs.com/Coeus-P/p/13769702.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!