Spark之wordcount程序原理深度剖析

wordCount源码:

/**
  *  
* * @author Sunny
* @version 1.0
* @CreateDate 2018-03-03 10:19
* @see com.spark.ruizhe
*/ 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!!") } }

深度分析如图:

Spark之wordcount程序原理深度剖析_第1张图片
image.png

你可能感兴趣的:(Spark之wordcount程序原理深度剖析)