Spark運行第一個Scala程式WordCount

  • 2019 年 12 月 26 日
  • 筆記

1、前置條件安裝

hadoop:https://blog.csdn.net/jxq0816/article/details/78736449

scala:https://www.runoob.com/scala/scala-install.html 2、Idea安裝Scala插件

3、程式碼

object ScalaWordCount {    def main(args: Array[String]): Unit = {      var lines = List("hello scala", "hello world","hello java")      //切分並壓平      val words = lines.flatMap(_.split(" "))      // 把每個單詞生成一個一個pair(key, 1)      val tuples = words.map((_, 1))      //以key進行分組 第一個_代表元組,第二個_1 代表key(單詞)      val gro