spark action 操作(1)

本文介绍了Apache Spark中几种常用的Action操作,包括first()、count()、collect()、take(n)、top(n)及takeOrdered(n)等,这些操作有助于高效地处理和检索分布式数据集中的数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面介绍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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值