作用:返回该RDD排序后的前n个元素组成的数组
package com.atguigu
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}
object Action {
def main(args: Array[String]): Unit = {
val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("ADCount")
val sc = new SparkContext(conf)
val rdd: RDD[Int] = sc.makeRDD(List(1,4,3,2))
val array: Array[Int] = rdd.takeOrdered(2)
array.foreach(println)
}
}
1
2
网友评论