返回排序后的前 n 个元素, 默认是升序排列.
    数据也会拉到 driver 端
    image.png

    1. def main(args: Array[String]): Unit = {
    2. val conf: SparkConf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")
    3. val sc: SparkContext = new SparkContext(conf)
    4. val rdd: RDD[Int] = sc.makeRDD(List(1, 3, 2, 4))
    5. val result: Array[Int] = rdd.takeOrdered(2)
    6. println(result.mkString(",")) //输出: 1,2
    7. sc.stop()
    8. }