RDD Opertions
    transformations:create a new dataset from an existing one
        RDDA --> RDDB
    actions: return a value to the driver program after running a computation on the dataset 
    
    
 For example, map is a transformation that passes each dataset element through a function and returns a new RDD representing the results. On the other hand, reduce is an action that aggregates all the elements of the RDD using some function and returns the final result to the driver program (although there is also a parallel reduceByKey that returns a distributed dataset).
 
 
All transformations in Spark are lazy, in that they do not compute their results right away. 
 
Instead, they just remember the transformations applied to some base dataset (e.g. a file). The transformations are only computed when an action requires a result to be returned to the driver program
 This design enables Spark to run more efficiently. For example, we can realize that a dataset created through map will be used in a reduce and return only the result of the reduce to the driver, rather than the larger mapped dataset.
 
 
def my_map():
    data = [1,2,3,4,5]
    rdd1 = sc.parallelize(data)
    rdd2 = rdd1.map(lambda x: x * 2 )
 
    print(rdd2.collect())
def my_filter():
    data = [1, 2, 3, 4, 5]
    # rdd1 = sc.parallelize(data)
    # rdd2 = rdd1.map(lambda x: x * 2)
    # rdd3 = rdd2.filter(lambda x:x > 5)
    # print(rdd3.collect())
 
    print(sc.parallelize(data).map(lambda x:x*2).filter(lambda x:x>5).collect())
 
 
 
def my_flatMap():
    data = ["hello spark","hello ming","hello clay"]
    print(sc.parallelize(data).flatMap(lambda line:line.split(" ")).collect())
 
 
 
 
 
def my_reduceByKey():
    data = ["hello spark","hello ming","hello clay"]
    rdd = sc.parallelize(data)
    mapRdd = rdd.flatMap(lambda line: line.split(" ")).map(lambda x:(x,1))
    my_reduceByKeyRdd = mapRdd.reduceByKey(lambda a,b:a+b)
    print(my_reduceByKeyRdd.collect())
 
 
 
 
 
union:
 
distinct:
 
join:
 
 
 
 
 

4.RDD常用算子之transformations的更多相关文章

  1. Spark Core核心----RDD常用算子编程

    1.RDD常用操作2.Transformations算子3.Actions算子4.SparkRDD案例实战 1.Transformations算子(lazy) 含义:create a new data ...

  2. Spark学习之路(四)—— RDD常用算子详解

    一.Transformation spark常用的Transformation算子如下表: Transformation算子 Meaning(含义) map(func) 对原RDD中每个元素运用 fu ...

  3. Spark 系列(四)—— RDD常用算子详解

    一.Transformation spark 常用的 Transformation 算子如下表: Transformation 算子 Meaning(含义) map(func) 对原 RDD 中每个元 ...

  4. spark学习(10)-RDD的介绍和常用算子

    RDD(弹性分布式数据集,里面并不存储真正要计算的数据,你对RDD的操作,他会在Driver端转换成Task,下发到Executor计算分散在多台集群上的数据) RDD是一个代理,你对代理进行操作,他 ...

  5. sparkRDD:第3节 RDD常用的算子操作

    4.      RDD编程API 4.1 RDD的算子分类 Transformation(转换):根据数据集创建一个新的数据集,计算后返回一个新RDD:例如:一个rdd进行map操作后生了一个新的rd ...

  6. RDD(弹性分布式数据集)及常用算子

    RDD(弹性分布式数据集)及常用算子 RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是 Spark 中最基本的数据 处理模型.代码中是一个抽象类,它代表一个 ...

  7. SparkRDD简介/常用算子/依赖/缓存

    SparkRDD简介/常用算子/依赖/缓存 RDD简介 RDD(Resilient Distributed Dataset)叫做分布式数据集,是Spark中最基本的数据抽象,它代表一个不可变.可分区. ...

  8. spark常用算子总结

    算子分为value-transform, key-value-transform, action三种.f是输入给算子的函数,比如lambda x: x**2 常用算子: keys: 取pair rdd ...

  9. 大数据学习day19-----spark02-------0 零碎知识点(分区,分区和分区器的区别) 1. RDD的使用(RDD的概念,特点,创建rdd的方式以及常见rdd的算子) 2.Spark中的一些重要概念

    0. 零碎概念 (1) 这个有点疑惑,有可能是错误的. (2) 此处就算地址写错了也不会报错,因为此操作只是读取数据的操作(元数据),表示从此地址读取数据但并没有进行读取数据的操作 (3)分区(有时间 ...

随机推荐

  1. P1802 5倍经验日

    P1802 5倍经验日 题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却无奈的看着那一些比他等级高的好友,想着能否把他们干掉.干掉能拿不少经验的. 题目描述 现在absi20 ...

  2. AtCoder ABC 127E Cell Distance

    题目链接:https://atcoder.jp/contests/abc127/tasks/abc127_e 题目大意 给定一个$N*M$的棋盘,二元组$(x, y),1 \leq x \leq N, ...

  3. PAT_A1102#Invert a Binary Tree

    Source: PAT A1102 Invert a Binary Tree (25 分) Description: The following is from Max Howell @twitter ...

  4. Android Telephony分析(一) ---- Phone详解

    目录: Phone的继承关系与PhoneFactory(GsmCdmaPhone.ImsPhone.SipPhone) Phone进程的启动 Phone对象的初始化(DefaultPhoneNotif ...

  5. Harry and magic string HDU - 5157 记录不相交的回文串对数

    题意: 记录不相交的回文串对数 题解: 正着反着都来一遍回文树 用sum1[i] 表示到 i 位置,出现的回文串个数的前缀和 sun2[i]表示反着的个数 ans+=sum1[i-1]*sum2[i] ...

  6. TFS 忽略 文件

    原文链接:http://ju.outofmemory.cn/entry/258689 让TFS忽略packages文件夹的更改 很多时候我们需要使用 Nuget 进行包管理,这时在我们的解决方案文件夹 ...

  7. JS,JQuery,获得选中的Radio值

    1.HTML代码 <input type=" checked="checked" /><label for="a1">男< ...

  8. Python全栈开发:django网络框架(二)

    Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层执行 ...

  9. MQTT--笔记

    一.MQTT协议基本介绍 1.1.MQTT是什么? MQTT,全称为Message Queue Telemetry Transport.在1999年,由IBM的Andy Stanford-Clark和 ...

  10. Java 基础 - 内存泄露Memory leak & 内存溢出Out of memory

    内存泄露 & 内存溢出 关系 https://www.cnblogs.com/panxuejun/p/5883044.html 内存泄露的6种情况: https://blog.csdn.net ...