Skip to content

Instantly share code, notes, and snippets.

@aorjoa
Last active October 3, 2016 17:28
Show Gist options
  • Select an option

  • Save aorjoa/11d909491430552ee977b110c1ac49ad to your computer and use it in GitHub Desktop.

Select an option

Save aorjoa/11d909491430552ee977b110c1ac49ad to your computer and use it in GitHub Desktop.
Test generate dataset GroupByTest Spark
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