Spark Operator: RDD Action Action (2) -take, top, takeOrdered
Take
Def take (num: Int): Array [T]Take is used to get RDD from 0 to num-1 subscript elements, not sort.
- Scala> var rdd1 = sc.makeRDD (Seq (10, 4, 2, 12, 3))
- Rdd1: org.apache.spark.rdd.RDD [Int] = ParallelCollectionRDD [40] at makeRDD at: 21
- Scala> rdd1.take (1)
- Res0: Array [Int] = Array (10)
- Scala> rdd1.take (2)
- Res1: Array [Int] = Array (10, 4)
Top
Def top (num: Int) (implicit ord: Ordering [T]): Array [T]The top function is used to return the preceding num elements from RDD, by default (descending) or by the specified collation.
- Scala> var rdd1 = sc.makeRDD (Seq (10, 4, 2, 12, 3))
- Rdd1: org.apache.spark.rdd.RDD [Int] = ParallelCollectionRDD [40] at makeRDD at: 21
- Scala> rdd1.top (1)
- Res2: Array [Int] = Array (12)
- Scala> rdd1.top (2)
- Res3: Array [Int] = Array (12, 10)
- // specify collation scala> implicit val myOrd = implicitly [Ordering [Int]]. Reverse
- MyOrd: scala.math.Ordering [Int] = scala.math.Ordering$$anon$4@767499ef
- Scala> rdd1.top (1)
- Res4: Array [Int] = Array (2)
- Scala> rdd1.top (2)
- Res5: Array [Int] = Array (2, 3)
TakeOrdered
Def takeOrdered (num: Int) (implicit ord: Ordering [T]): Array [T]TakeOrdered is similar to top, except that the elements are returned in the reverse order of top.
For more information on the Spark operator, refer to the Spark operator series .
- Scala> var rdd1 = sc.makeRDD (Seq (10, 4, 2, 12, 3))
- Rdd1: org.apache.spark.rdd.RDD [Int] = ParallelCollectionRDD [40] at makeRDD at: 21
- Scala> rdd1.top (1)
- Res4: Array [Int] = Array (2)
- Scala> rdd1.top (2)
- Res5: Array [Int] = Array (2, 3)
- Scala> rdd1.takeOrdered (1)
- Res6: Array [Int] = Array (12)
- Scala> rdd1.takeOrdered (2)
- Res7: Array [Int] = Array (12, 10)
Commentaires
Enregistrer un commentaire