您的位置:首页 > 其它

spark action 操作(1)

2016-05-26 22:19 393 查看
下面介绍spark的几个action操作:

1、first(),返回RDD中的第一个元素(不排序)。

     def first(): T               // Return the first element in this RDD.

2、count(),返回RDD中的元素数量。

     def count(): Long      //Return the number of elements in the RDD.

3、collect(),返回一个包含RDD中所有元素的数组。

     def collect(): Array[T]      //Return an array that contains all of the elements in this RDD.

4、take(n),用于获取RDD中从0到n-1下标的元素,不排序。

     def take(num: Int): Array[T]     //Take the first num elements of the RDD. It works by first scanning one partition, and use the results from that partition to estimate the number of additional partitions needed to satisfy
the limit.

5、top(n),用于从RDD中,按照默认(降序)或者指定的排序规则,返回前n个元素。

     def top(num: Int)(implicit ord: Ordering[T]): Array[T]      

     //Returns the top k (largest) elements from this RDD as defined by the specified implicit Ordering[T] and maintains the ordering.

6、takeOrdered(n),takeOrdered和top类似,只不过和top相反的顺序返回元素。

     def takeOrdered(num: Int)(implicit ord: Ordering[T]): Array[T]

     //Returns the first k (smallest) elements from this RDD as defined by the specified implicit Ordering[T] and maintains the ordering.





Reference:

             https://spark.apache.org/docs/1.6.0/api/scala/index.html#org.apache.spark.rdd.RDD

             http://lxw1234.com/archives/2015/07/363.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: