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(zeroValueop)

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(keyfuncascending=TruenumPartitions=None)

Sorts this RDD by the given keyfunc

例子:

Spark Programming--Actions的更多相关文章

  1. <Spark><Programming><RDDs>

    Introduction to Core Spark Concepts driver program: 在集群上启动一系列的并行操作 包含应用的main函数,定义集群上的分布式数据集,操作数据集 通过 ...

  2. <Spark><Programming><Key/Value Pairs><RDD>

    Working with key/value Pairs Motivation Pair RDDs are a useful building block in many programs, as t ...

  3. Spark Programming Guide《翻译》

    转载必须注明出处:梁杰帆 在这里要先感谢原作者们!如果各位在这里发现了错误之处,请大家提出 1.Initializing Spark     Spark程序必须做的第一件事就是创建一个SparkCon ...

  4. <Spark><Programming><Loading and Saving Your Data>

    Motivation Spark是基于Hadoop可用的生态系统构建的,因此Spark可以通过Hadoop MapReduce的InputFormat和OutputFormat接口存取数据. Spar ...

  5. Spark Streaming Programming Guide

    参考,http://spark.incubator.apache.org/docs/latest/streaming-programming-guide.html Overview SparkStre ...

  6. Apache Spark 2.2.0 中文文档 - GraphX Programming Guide | ApacheCN

    GraphX Programming Guide 概述 入门 属性 Graph 示例属性 Graph Graph 运算符 运算符的汇总表 Property 运算符 Structural 运算符 Joi ...

  7. Spark快速入门 - Spark 1.6.0

    Spark快速入门 - Spark 1.6.0 转载请注明出处:http://www.cnblogs.com/BYRans/ 快速入门(Quick Start) 本文简单介绍了Spark的使用方式.首 ...

  8. zhihu spark集群,书籍,论文

    spark集群中的节点可以只处理自身独立数据库里的数据,然后汇总吗? 修改 我将spark搭建在两台机器上,其中一台既是master又是slave,另一台是slave,两台机器上均装有独立的mongo ...

  9. Spark Streaming编程指南

    Overview A Quick Example Basic Concepts Linking Initializing StreamingContext Discretized Streams (D ...

  10. Spark Streaming核心概念与编程

    Spark Streaming核心概念与编程 1. 核心概念 StreamingContext Create StreamingContext import org.apache.spark._ im ...

随机推荐

  1. BZOJ3906 : Trie

    将输入的Trie建成AC自动机,并建出fail树. 那么操作1等价于在给定点的子树的并集里都加1. 操作2等价于查询给定点到根节点路径的并集的权值和. 求出DFS序后,对于操作1,将点按进入时间戳从小 ...

  2. BZOJ3837 : [Pa2013]Filary

    当m取2时,k至少为$\frac{n}{2}$ 所以在最优解中每个数被选中的概率至少为$\frac{1}{2}$ 每次随机选取一个位置i,计算出其它数与$a_i$的差值,将差值分解质因数 所有质因数中 ...

  3. POJ 3020 (二分图+最小路径覆盖)

    题目链接:http://poj.org/problem?id=3020 题目大意:读入一张地图.其中地图中圈圈代表可以布置卫星的空地.*号代表要覆盖的建筑物.一个卫星的覆盖范围是其周围上下左右四个点. ...

  4. Grunt配置文件编写技巧及示范

    受益于grunt这么久,继续分享关于grunt的一些技巧.grunt确实是前端项目中不可或缺的提升效率的工具.第一次接触grunt是在去年7月份,开始有接触LESS.Coffee Script的等需要 ...

  5. HDU 4671 Partition(定理题)

    题目链接 这题,明显考察搜索能力...在中文版的维基百科中找到了公式. #include <cstdio> #include <cstring> #include <st ...

  6. e.KeyChar用到的键盘对应ASCII码值(转)

    十进制编码 (对应)缩写字符(或功能/解释)   0 NUL(null) 空字符   1 SOH(start of headline) 标题开始   2 STX (start of text) 正文开 ...

  7. HTML5 :b/strong加粗,i/em倾斜区别

    解释1 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="ut ...

  8. 新浪SAE数据库连接demo和说明

    <?php $con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); // ...

  9. 2016.07.08,英语,《Vocabulary Builder》Unit 24

    mand/mend comes from mandare, Latin for 'entrust' or 'order'. command and commandment: [kə'mændmənt] ...

  10. php实现上传图片保存到数据库的方法

    http://www.jb51.net/article/61034.htm 作者:傲雪星枫 字体:[增加 减小] 类型:转载   这篇文章主要介绍了php实现上传图片保存到数据库的方法,可通过将图片保 ...