Skip to content

Instantly share code, notes, and snippets.

@malaikannan
Created February 2, 2016 06:11
Show Gist options
  • Save malaikannan/8b42e94d6edd0aa3d58b to your computer and use it in GitHub Desktop.
Save malaikannan/8b42e94d6edd0aa3d58b to your computer and use it in GitHub Desktop.
/**
* Created by malai on 2/1/16.
*/
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
object WordCount {
def main(args:Array[String]) : Unit = {
val logFile = "/home/malai/spark-1.6.0/README.md"
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val input = sc.textFile(logFile)
val words = input.flatMap(line => line.split(" "))
val counts = words.map(word => (word,1)).reduceByKey{case(x,y) => x + y}
counts.saveAsTextFile("/home/malai/spark-1.6.0/README_log1.md")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment