文章目录
- -*- coding: utf-8 -*-
- Program function:完成单Value类型RDD的转换算子的演示
- 1-创建SparkContext申请资源
- 2-key和value类型算子
- groupByKey
- [('b', <pyspark.resultiterable.ResultIterable object at 0x7f001c469c40>),
- ('c', <pyspark.resultiterable.ResultIterable object at 0x7f001c469310>),
- ('a', <pyspark.resultiterable.ResultIterable object at 0x7f001c469a00>)]
- reduceByKey
- sortByKey
- countByKey
- -*- coding: utf-8 -*-
- Program function:完成单Value类型RDD的转换算子的演示
- 1-创建SparkContext申请资源
- 2-foreach-Applies a function to all elements of this RDD.
- def f(x):print(x)
- 3-foreachPartition--Applies a function to each partition of this RDD.
- 从性能角度分析,按照分区并行比元素更加高效
- 4-map---按照元素进行转换
- 5-mapPartiton-----按照分区进行转换
- Return a new RDD by applying a function to each partition of this RDD.
- TODO: 1-创建SparkContext申请资源
- TODO: 2-基础数据处理
- [(a:[1,1]),(b,[1,1])]
- 使用自定义集聚合函数组合每个键的元素的通用功能。
- - `createCombiner`, which turns a V into a C (e.g., creates a one-element list)
- 对初始值进行操作
- - `mergeValue`, to merge a V into a C (e.g., adds it to the end ofa list)
- 对分区内的元素进行合并
- - `mergeCombiners`, to combine two C's into a single one (e.g., merges the lists)
- 对分区间的元素进行合并
- -*- coding: utf-8 -*-
- Program function:完成单Value类型RDD的转换算子的演示
- TODO: 1-创建SparkContext申请资源
- TODO: 2-基础数据处理
- 这里需要实现需求:求解一个学生的平均成绩
- 第一个分区("Fred", 88), ("Fred", 95)
- 第二个分区("Fred", 91), ("Wilma", 93),
- 第三个分区("Wilma", 95), ("Wilma", 98)
- reduceByKey
- 如何求解平均成绩?
- 使用自定义集聚合函数组合每个键的元素的通用功能。
- - `createCombiner`, which turns a V into a C (e.g., creates a one-element list)
- 对初始值进行操作
- - `mergeValue`, to merge a V into a C (e.g., adds it to the end ofa list)
- 对分区内的元素进行合并
- - `mergeCombiners`, to combine two C's into a single one (e.g., merges the lists)
- 对分区间的元素进行合并
- 接下来平均值如何实现--('Fred', [274, 3])---x[0]=Fred x[1]= [274, 3],x[1][0]=274,x[1][1]=3
RDD的操作
函数分类
Transformation函数
Action函数
基础练习[Wordcount快速演示]
Transformer算子
Action算子
重要函数
后记
📢博客主页:https://manor.blog.csdn.net
📢欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请指正!
📢本文由 Maynor 原创,首发于 CSDN博客🙉
📢感觉这辈子,最深情绵长的注视,都给了手机⭐
📢专栏持续更新,欢迎订阅:https://blog.csdn.net/xianyu120/category_12453356.html