当前位置:网站首页>05 Spark on 读取内部数据分区存储策略(源码角度分析)
05 Spark on 读取内部数据分区存储策略(源码角度分析)
2022-08-08 23:31:00 【YaPengLi.】
Spark-读取内部数据分区存储策略源码角度分析
Spark-读取内部数据分区策略(源码角度分析):https://blog.csdn.net/lucklilili/article/details/115432028
针对下面代码片段源码角度进行分析,创建RDD并且调用saveAsTextFile()函数,最终执行结果为part-00000 => 1、part-00000 => 2 3、part-00003 => 4 5
Step1:
调用makeRDD函数,长度size = 5,分区数numSlices = 3。
Step2:
调用parallelize函数,长度size = 5,数据1、2、3、4、5,分区数numSlices = 3。
Step3:
调用parallelize的getPartitions函数,长度size = 5,数据1、2、3、4、5,分区数numSlices = 3。
Step4:
执行slice函数的case模式匹配,长度size = 5,数据1、2、3、4、5,分区数numSlices = 3。
Step5:
调用本函数里面positions方法,长度size = 5,分区数numSlices = 3 。
// Sequences need to be sliced at the same set of index positions for operations
// like RDD.zip() to behave as expected
def positions(length: Long, numSlices: Int): Iterator[(Int, Int)] = {
(0 until numSlices).iterator.map { i =>
val start = ((i * length) / numSlices).toInt
val end = (((i + 1) * length) / numSlices).toInt
(start, end)
}
}
1:
var start = (0 * 5) / 3 = 0
var end =((0 + 1) * 5) /3 = 1
2:
var start = (1 * 5) / 3 = 1
var end =((1 + 1) * 5) / 3 = 3
3:
var start = (2 * 5) / 3 = 3
var end =((2 + 1) * 5) / 3 = 5
Step6:
循环遍历调用slice函数
数据:1,2,3,4,5
每次执行slice()后得的结果(0,1),(1,3),(3,5),最终结果如:
(0,1) = 1 => part00000
(1,3) = 2,3 => part00001
(3,5) => 4,5 => part00001
边栏推荐
猜你喜欢
随机推荐
可以在易方达基金上买基金吗,安全吗
洛谷P4197 Peaks 线段树合并
【YOLOv5】6.0环境搭建(不定时更新)
用工具实现 Mock API 的整个流程
第二课:概率论
(2022杭电多校六)1010-Planar graph(最小生成树)
mysql主从复制
LeetCode:最长有效括号
(2022杭电多校三)1011.Taxi(曼哈顿最值+二分)
WeChat applet error undefined Expecting 'STRING','NUMBER','NULL','TRUE','FALSE','{','[', got ]Solution
(2022牛客多校三)A-Ancestor(LCA)
Use Mongoose populate to implement multi-table associative storage and query, with complete code included
(2022杭电多校四)1001-Link with Bracket Sequence II(区间动态规划)
2022杭电多校六 1006-Maex (树形DP)
2022杭电多校六 1007-Shinobu loves trip(同余方程)
用模态框 实现 注册 登陆
51nod 2887 抓小偷 平面图最小割转换成最短路
机器学习建模高级用法!构建企业级AI建模流水线
使用Mongoose populate实现多表关联存储与查询,内附完整代码
Binary tree level traversal and examples