Skip to content

Instantly share code, notes, and snippets.

@mizvol
Last active July 17, 2017 20:49
Show Gist options
  • Save mizvol/925deaa88e2f47ed17a2f8a866bf196f to your computer and use it in GitHub Desktop.
Save mizvol/925deaa88e2f47ed17a2f8a866bf196f to your computer and use it in GitHub Desktop.
import org.apache.spark.sql.SparkSession
object SparkWordCount extends App {
val spark = SparkSession.builder
.master("local[*]")
.appName("Spark Word Count")
.getOrCreate()
val lines = spark.sparkContext.parallelize(
Seq("Spark Intellij Idea Scala test one",
"Spark Intellij Idea Scala test two",
"Spark Intellij Idea Scala test three"))
val counts = lines
.flatMap(line => line.split(" "))
.map(word => (word, 1))
.reduceByKey(_ + _)
counts.foreach(println)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment