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. 直接用编译器按ctrl+F5运行和双击运行结果不一样

    是因为进程权限的问题,需要添加下面的代码: BOOL EnableDebugPrivilege() { HANDLE hToken; BOOL fOk=FALSE; if(OpenProcessTok ...

  2. iOS开发之3D Touch

    1.简介 3DTouch是在6s之后苹果的一项技术,只能在6s及其以上机型真机运行,Xcode的模拟器是不支持的. Quick Actions(点击icon的快捷方式) Peek&Pop(应用 ...

  3. selenium+python 绕过登录进行测试

    多个Py文件进行多线程测试时,每次登录是很麻烦的事情,所以通过cookie登录,可以绕过登录操作      但是至少需要正常登录一次才能获取到cookie 然后使用cookies进行登录

  4. 取地址栏query

    GetQueryParm () { var name, value       var str = window.location.href       var num = str.indexOf(' ...

  5. 连接mysql并查询

    1.将mysql-connector-java-5.1.7-bin.jar放入Jmeter安装目录的bin文件夹中 2.在顶层目录<测试计划>中加载驱动 3.添加JDBC Connecti ...

  6. 004-Java进制转换

    整型数据共有4中进制形式 二进制(binary):以0b或者0B开头 十进制(decimal) 八进制(octal):以数字0开头 十六进制(hex):以0x或者0X开头 二进制数据包含原码反码和补码 ...

  7. Immutable 想破坏它也没办法

    上一章讲的是线程互斥的synchronized实现,这样做会影响性能,如何才能做到既不影响性能又能达到线程安全的目的呢,就是使用状态绝不会改变的类,Java中的应用就是String类. public ...

  8. 找到你的位置(JS在页面中的位置)最常用的方式是在页面中head部分放置<script>元素,浏览器解析head部分就会执行这个代码,然后才解析页面的其余部分

    找到你的位置(JS在页面中的位置) 我们可以将JavaScript代码放在html文件中任何位置,但是我们一般放在网页的head或者body部分. 放在<head>部分 最常用的方式是在页 ...

  9. Android Studio Gradle无法获取pom文件

    错误提示: Error:Execution failed for task ':app:lintVitalRelease'. > Could not resolve all artifacts ...

  10. JavaScript工作原理

    HTML代码所表示的文档是一种静态文档,几乎没有交互功能,很难使页面成为动态页面.增加脚本语言,可使数据发送到服务器之前先进行处理和校验,动态地创建新的Web内容,更重要的是,引入脚本语言使我们有了事 ...