indows Eclipse Scala編寫WordCount程式 ...
Windows Eclipse Scala編寫WordCount程式:
1)無需啟動hadoop,因為我們用的是本地文件。先像原來一樣,做一個普通的scala項目和Scala Object。
但這裡一定註意版本是2.10.6,因為預設的不好使。改的方法是:右擊項目/properties/Scala Compiler.
2)像spark的java版WordCount項目一模一樣導包,什麼都一樣。(導包的方法和原來普通的java項目一樣)
例:5.1
package com
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
object WordCount {
def main(args: Array[String]) {
val conf = new SparkConf();
conf.setAppName("First Spark scala App!");
conf.setMaster("local");
val sc = new SparkContext(conf);
val lines = sc.textFile("E://temp//input//friend.txt", 1);
val words = lines.flatMap { lines => lines.split(" ") };
val pairs = words.map { word => (word, 1) }
val wordCounts = pairs.reduceByKey(_ + _)
wordCounts.foreach(wordNumberPair => println(wordNumberPair._1 + ":" + wordNumberPair._2))
}
}
文章轉載自原文:https://blog.csdn.net/qq_44596980/article/details/93383684