Last active
October 3, 2016 17:28
-
-
Save aorjoa/11d909491430552ee977b110c1ac49ad to your computer and use it in GitHub Desktop.
Test generate dataset GroupByTest Spark
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 java.util.Random | |
| import org.apache.spark.{SparkConf, SparkContext} | |
| import org.apache.spark.SparkContext._ | |
| var numMappers = 100 | |
| var numKVPairs = 10000 | |
| var valSize = 1000 | |
| var numReducers = 36 | |
| val pairs1 = sc.parallelize(0 until numMappers, numMappers).flatMap { p => | |
| val ranGen = new Random | |
| var arr1 = new Array[(Int, Array[Byte])](numKVPairs) | |
| for (i <- 0 until numKVPairs) { | |
| val byteArr = new Array[Byte](valSize) | |
| ranGen.nextBytes(byteArr) | |
| arr1(i) = (i, byteArr) | |
| } | |
| arr1 | |
| }.cache | |
| // Enforce that everything has been calculated and in cache | |
| pairs1.count | |
| pairs1.groupByKey(numReducers).count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment