Skip to content

Instantly share code, notes, and snippets.

@bryanyang0528
Last active August 29, 2015 14:09
Show Gist options
  • Save bryanyang0528/234cb6a638da2db213ad to your computer and use it in GitHub Desktop.
Save bryanyang0528/234cb6a638da2db213ad to your computer and use it in GitHub Desktop.
RDD Sample
val num = 1 to 100
//num: scala.collection.immutable.Range.Inclusive = Range(1,2,3,...,100)
val numRDD = sc.parallelize(num)
//numRDD: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[11] at parallelize at <console>:14
val numFileter = numRDD.filter(_ < 10)
//numFileter: org.apache.spark.rdd.RDD[Int] = FilteredRDD[12] at filter at <console>:16
val numMap = numFileter.map(_ + 10)
//numMap: org.apache.spark.rdd.RDD[Int] = MappedRDD[13] at map at <console>:18
val numSum = numMap.reduce(_ + _)
//numSum: Int = 135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment