Spark学习笔记 --- scala实现Spark wordcount例子
2017-03-07 22:57
405 查看
package wordcount.WordCount import org.apache.spark.SparkConf import org.apache.spark.SparkContext /** * Created by Ryan on 2017/3/7. */ object scala { def main(args: Array[String]) : Unit = { val conf = new SparkConf() conf.setAppName("WordCountApplication") conf.setMaster("local") val sc = new SparkContext(conf) val lines = sc.textFile("/usr/softwares/spark/ReadMe.md", 3) val words = lines.flatMap{line => line.split(" ")} val pairs = words.map(words => (words, 1)) val wordCounts = pairs.reduceByKey(_+_) wordCounts.foreach(wordNumberPair => println(wordNumberPair._1 + " : " + wordNumberPair._2)) sc.stop() } }
相关文章推荐
- Scala中链式调用风格的实现代码实战及其在Spark编程中的广泛运用之Scala学习笔记-41
- 第51讲:Scala中链式调用风格的实现代码实战及其在Spark编程中的广泛运用学习笔记
- Flink学习笔记 --- scala实现Flink的DataSet Source进行WordCount
- Spark学习笔记@第一个例子wordcount+Eclipse
- 第43讲:Scala中类型变量Bounds代码实战及其在Spark中的应用源码解析学习笔记
- what's in string? c语言string类函数实现汇总 都是学习使用指针的好例子啊(算是读书摘抄和笔记吧)
- 第47讲:Scala多重界定代码实战及其在Spark中的应用源码解析学习笔记
- Spark 学习笔记:(二)编程指引(Scala版)
- 第50讲:Scala中Variance变化点及其在Spark中的应用源码解析学习笔记
- 第44讲:Scala中View Bounds代码实战及其在Spark中的应用源码解析学习笔记
- 第45讲:Scala中Context Bounds代码实战及其在Spark中的应用源码解析学习笔记
- what's in string? c语言string类函数实现汇总 觉得都是学习使用指针的好例子(算是读书摘抄和笔记吧)
- Spark学习笔记-KNN算法实现
- Scala中泛型类、泛型函数、泛型在Spark中的广泛应用之Scala学习笔记-33
- Scala中View Bounds代码实战及其在Spark中的应用源码解析之Scala学习笔记-35
- 第89讲:Scala中使用For表达式实现内幕思考学习笔记
- Scala 学习笔记(6)-程序例子Scala Keams聚类算法
- spark学习笔记一:scala语言基础
- 第42讲:Scala中泛型类、泛型函数、泛型在Spark中的广泛应用学习笔记
- 第82讲:Scala中List的ListBuffer是如何实现高效的遍历计算的?学习笔记