其他分享
首页 > 其他分享> > Spark—WordCount

Spark—WordCount

作者:互联网

 

 

 

本地模式

import org.apache.spark.SparkContext
import org.apache.spark.SparkConf

object WordCount {
  def main(args: Array[String]) {
    val conf = new SparkConf().setAppName("WordCount").setMaster("local[2]")
    val sc = new SparkContext(conf)   
    val inputFile = sc.textFile("/user/wd")
    val wordCount = inputFile.flatMap(_.split(" ")).map(word => (word, 1)).reduceByKey((a, b) => a + b)
    wordCount.foreach(println)
    sc.stop()
  }
}

 

标签:SparkContext,val,WordCount,conf,sc,Spark,inputFile
来源: https://www.cnblogs.com/ojbtospark/p/15220518.html