import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} //map(func) object sampleRDD { def main(args: Array[String]): Unit = { //本地模式 val conf: SparkConf = new SparkConf().setAppName("My scala word count").setMaster("local") //创建spark上下文对象 val sc = new SparkContext(conf) val rdd: RDD[Int] = sc.makeRDD(1 to 10) val value: Any = rdd.sample(true,0.1,0) println(value) val ints: Array[Int] = rdd.takeSample(true,3,1) println(ints.mkString(",")) } }