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!!")
}
}
深度分析如圖: