Skip to content

Instantly share code, notes, and snippets.

@abdolence
Last active March 19, 2020 21:06
Show Gist options
  • Save abdolence/fb81068263a915530c7de24b7759908a to your computer and use it in GitHub Desktop.
Save abdolence/fb81068263a915530c7de24b7759908a to your computer and use it in GitHub Desktop.
val conf = new SparkConf()
//.setMaster("local") for local development
.setAppName("FizzBuzz App")
val spark = SparkSession
.builder()
.config(conf)
.getOrCreate()
import spark.implicits._
def basicFizzbuzzRules( x: Long ): String = {
( x % 3, x % 5 ) match {
case ( 0, 0 ) => "FizzBuzz"
case ( 0, _ ) => "Fizz"
case ( _, 0 ) => "Buzz"
case _ => x.toString
}
}
val N = 10000000
spark
.range(1, N)
.repartition(10) // chose the number partitions you want
.map(x => (x, basicFizzbuzzRules(x)))
.write
.csv("/tmp/fizzbuzz-spark")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment