美文网首页
Spark之wordcount程序原理深度剖析

Spark之wordcount程序原理深度剖析

作者: SunnyMore | 来源:发表于2018-05-23 10:50 被阅读14次

wordCount源码:

/**
  * <Description> <br>
  *
  * @author Sunny<br>
  * @version 1.0<br>
  * @CreateDate 2018-03-03 10:19 <br>
  * @see com.spark.ruizhe <br>
  */
object WordCount {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setAppName("WorldCount").setMaster("local")
    val sparkContext = new SparkContext(sparkConf)
    val lines = sparkContext.textFile("E:\\workspace\\workspace_spark\\workspace_spark_scala\\test.txt")
    val words = lines.flatMap(line => line.split(" "))
    val pairs = words.map(word => (word, 1))
    val wordsCount = pairs.reduceByKey(_ + _)
    wordsCount.foreach(tuple => println(tuple._1 + " appears " + tuple._2 + " times"))
    println("finished!!")
  }
}

深度分析如图:

image.png

相关文章

网友评论

      本文标题:Spark之wordcount程序原理深度剖析

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