Spark Programming--Actions
first
def first(): T
first返回RDD中的第一个元素,不排序。
例子:

count
def count(): Long
count返回RDD中的元素数量
例子:

reduce
def reduce(f: (T, T) ⇒ T): T
根据映射函数f,对RDD中的元素进行二元计算,返回计算结果(可用于求和,字符串叠加等等)
例子:

take
def take(num: Int): Array[T]
take用于获取RDD中从0到num-1下标的元素,不排序
例子:

top
def top(num: Int)(implicit ord: Ordering[T]): Array[T]
top函数用于从RDD中,按照默认(降序)或者指定的排序规则,返回前num个元素
例子:(注意与take区别)

takeOrdered
def takeOrdered(num: Int)(implicit ord: Ordering[T]): Array[T]
takeOrdered和top类似,只不过以和top相反的顺序返回元素
例子:(注意与take、top比较)

aggregate
fold
fold(zeroValue, op)
Aggregate the elements of each partition, and then the results for all the partitions, using a given associative and commutative function and a neutral “zero value.”
类似于给一个初值和一个函数,将rdd中每一个值累加到zeroValue中
例子:

lookup
lookup(key)
Return the list of values in the RDD for key key. This operation is done efficiently if the RDD has a known partitioner by only searching the partition that the key maps to.
lookup用于(K,V)类型的RDD,指定K值,返回RDD中该K对应的所有V值
例子:(查询)

countByKey
Count the number of elements for each key, and return the result to the master as a dictionary.
countByKey用于统计RDD[K,V]中每个K的数量
例子:

foreach
foreach(f)
foreach用于遍历RDD,将函数f应用于每一个元素。
但要注意,如果对RDD执行foreach,只会在Executor端有效,而并不是Driver端。
比如:rdd.foreach(println),只会在Executor的stdout中打印出来,Driver端是看不到的。
跟accumulator结合很有效
例子:

foreachPartition
Applies a function to each partition of this RDD.
例子:

sortBy
sortBy(keyfunc, ascending=True, numPartitions=None)
Sorts this RDD by the given keyfunc
例子:

Spark Programming--Actions的更多相关文章
- <Spark><Programming><RDDs>
Introduction to Core Spark Concepts driver program: 在集群上启动一系列的并行操作 包含应用的main函数,定义集群上的分布式数据集,操作数据集 通过 ...
- <Spark><Programming><Key/Value Pairs><RDD>
Working with key/value Pairs Motivation Pair RDDs are a useful building block in many programs, as t ...
- Spark Programming Guide《翻译》
转载必须注明出处:梁杰帆 在这里要先感谢原作者们!如果各位在这里发现了错误之处,请大家提出 1.Initializing Spark Spark程序必须做的第一件事就是创建一个SparkCon ...
- <Spark><Programming><Loading and Saving Your Data>
Motivation Spark是基于Hadoop可用的生态系统构建的,因此Spark可以通过Hadoop MapReduce的InputFormat和OutputFormat接口存取数据. Spar ...
- Spark Streaming Programming Guide
参考,http://spark.incubator.apache.org/docs/latest/streaming-programming-guide.html Overview SparkStre ...
- Apache Spark 2.2.0 中文文档 - GraphX Programming Guide | ApacheCN
GraphX Programming Guide 概述 入门 属性 Graph 示例属性 Graph Graph 运算符 运算符的汇总表 Property 运算符 Structural 运算符 Joi ...
- Spark快速入门 - Spark 1.6.0
Spark快速入门 - Spark 1.6.0 转载请注明出处:http://www.cnblogs.com/BYRans/ 快速入门(Quick Start) 本文简单介绍了Spark的使用方式.首 ...
- zhihu spark集群,书籍,论文
spark集群中的节点可以只处理自身独立数据库里的数据,然后汇总吗? 修改 我将spark搭建在两台机器上,其中一台既是master又是slave,另一台是slave,两台机器上均装有独立的mongo ...
- Spark Streaming编程指南
Overview A Quick Example Basic Concepts Linking Initializing StreamingContext Discretized Streams (D ...
- Spark Streaming核心概念与编程
Spark Streaming核心概念与编程 1. 核心概念 StreamingContext Create StreamingContext import org.apache.spark._ im ...
随机推荐
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- css expression
概述 css expression(css表达式)又称Dynamic properties(动态属性)是早期微软DHTML的产物,以其可以在Css中定义表达式(公式)来达到建立元素间属性之间的联系等作 ...
- Jexus & Mono 迁移
具体案例: 问: 这个是现在微信公共平台的进三月请求数合计 如果迁移到 Mono & Jexus 需要注意那些? 因为微信需要的是5秒响应,服务号存在时段高峰值,在峰值上,一台服务器能否 ...
- NOIP200107统计单词个数
NOIP200107统计单词个数 难度级别: A: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给出一个长度不超过200的由 ...
- iOS-TextField知多少
iOS-TextField知多少 //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRect ...
- Qt connect parent widget 连接父控件的信号槽
Qt中的信号槽系统是不同类中间传递数据的神器,如果连接父子空间之间的信号槽很重要,在父类中实例化子类的时候一定要注意将父类连上,不然信号槽无法使用,比如若子类是个对话框Dialog类,一定不要忘了加t ...
- 错误之thinkphp模型使用发生的错误
刚接触thinkphp模型的创建,在创建model类时在这里边声明了类的对象.唉,这是不理解的错误啊.什么叫做实例化模型对象,在控制器里边使用才创建. 模型这里写各种用到的函数. 这里我也体会到了查询 ...
- CVE-2013-3908 Internet Explorer打印预览功能可导致信息泄露
原文:http://masatokinugawa.l0.cm/2014/11/ie-printpreview-infoleak.html 问题1: 在IE9和以前的版本当中进行打印预览操作时,IE会取 ...
- java 文件读写
http://blog.csdn.net/jiangxinyu/article/details/7885518
- Self Service Password (SSP)
安装SSP, 依赖包包括php5, php5-ldap, php5-mcrypt 启用mcrypt功能: sudo php5enmod mcrypt 第一部分: Apache 安装Apache, 并且 ...