Spark教程
1、取正序前k个数
scala> var rdd1=sc.makeRDD(Seq(8,3,6,2,5)) rdd1: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[0] at makeRDD at <console>:24 scala> var myOrder1=implicitly[Ordering[Int]] myOrder1: Ordering[Int] = scala.math.Ordering$Int$@45127d5b scala> rdd1.takeOrdered(3)(myOrder1) res0: Array[Int] = Array(2, 3, 5)2、取逆序前k个数
scala> var rdd1=sc.makeRDD(Seq(8,3,6,2,5)) rdd1: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[0] at makeRDD at <console>:24 scala> val myOrder2=implicitly[Ordering[Int]].reverse myOrder2: scala.math.Ordering[Int] = scala.math.Ordering$$anon$4@2f43af5 scala> rdd1.takeOrdered(3)(myOrder2) res1: Array[Int] = Array(8, 6, 5)