Last active
March 19, 2020 21:06
-
-
Save abdolence/fb81068263a915530c7de24b7759908a to your computer and use it in GitHub Desktop.
This file contains 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
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