spark wordcount

来源:互联网 发布:vb编程入门书籍 编辑:程序博客网 时间:2024/06/05 11:00

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
object WordCount {
     def main(args: Array[String]) {
           val conf = new SparkConf()
           conf.setAppName("WordCount")
           val sc = new SparkContext(conf)
           val file = "hdfs://127.0.0.1:9000/file.txt"
           val lines = sc.textFile(file)
           val words = lines.flatMap(_.split("\\s+"))
           val wordCount = words.countByValue() println(wordCount)
    }
}


原创粉丝点击