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. 扩展BSGS-传送门

    很好的讲解:ZigZagK 好的讲解:mjtcn 某个模板:here 模板题: BSGS:ZigZagK的poj2417 exBSGS:ZigZagK的poj3243 — AC_Gibson 一般的板 ...

  2. 秒懂机器学习---分类回归树CART

    秒懂机器学习---分类回归树CART 一.总结 一句话总结: 用决策树来模拟分类和预测,那些人还真是聪明:其实也还好吧,都精通的话想一想,混一混就好了 用决策树模拟分类和预测的过程:就是对集合进行归类 ...

  3. "Access denied for user 'root@localhost' 试一下你的mysql是不是用任何密码都可以登录,如果是的话这里

    https://blog.csdn.net/light_breeze/article/details/82070222 花了三小时...竟然是因为这个

  4. centos7.4安装kubernetes1.6.0(开启TLS认证)

    目录 目录 前言 集群详情 环境说明 安装前准备 提醒 一.创建TLS证书和秘钥 安装CFSSL 创建 CA (Certificate Authority) 创建 CA 配置文件 创建 CA 证书签名 ...

  5. SpringBoot通过maven打包成jar,设定主清单属性。

    文章目录 原来普通的jar包一直是 <build> <plugins> <plugin> <groupId>org.apache.maven.plugi ...

  6. Git仓库操作命令

    创建仓库 git init 在当前目录执行,会生成.git目录文件,这个和SVN一致. 提交到仓库 git commit -m "first commit" -m:表示提交描述,必 ...

  7. 22-Ubuntu-文件和目录命令-移动文件和目录-mv

    mv 可以用来移动文件或目录,也可以给文件或目录重命名. 选项 含义 -i 覆盖文件前提示 1.移动文件和目录 1-1移动文件 例: 将当前目录下的123.txt文件移动到~/桌面/b/e目录下 mv ...

  8. 9-MySQL高级-主从同步时Slave_IO_Running:Connecting ; Slave_SQL_Running:Yes的情况故障排除

    推荐!! 各种情况都考虑在内,条理清楚!! https://blog.csdn.net/mbytes/article/details/86711508

  9. Vagrant安装步骤

    Vagrant安装步骤 下载添加box镜像 vagrant box add base 远端的box地址或者本地的box文件名 建立box镜像关联 vagrant box add centos72 va ...

  10. bzoj 3579: 破冰派对

    题意: 给你一个图,问你有多少个方案把他分成连个新的图.使得一个图是一个团,另外一个是独立集 一些闲话: 以前做过一次这个题..当时听说爆搜可以过,就无脑莽过去了.. 也没有思考为什么爆搜能过,或者有 ...