返回排序后的前 n 个元素, 默认是升序排列.
数据也会拉到 driver 端
def main(args: Array[String]): Unit = {
val conf: SparkConf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")
val sc: SparkContext = new SparkContext(conf)
val rdd: RDD[Int] = sc.makeRDD(List(1, 3, 2, 4))
val result: Array[Int] = rdd.takeOrdered(2)
println(result.mkString(",")) //输出: 1,2
sc.stop()
}