Last active
July 17, 2017 20:49
-
-
Save mizvol/925deaa88e2f47ed17a2f8a866bf196f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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