当前位置:网站首页>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
边栏推荐
猜你喜欢
【CUDA】version switch freely
容斥原理
WeChat applet error undefined Expecting 'STRING','NUMBER','NULL','TRUE','FALSE','{','[', got ]Solution
ViewOverlay与ViewGroupOverlay
第二课:概率论
(2022牛客多校四)A-Task Computing (排序+动态规划)
WeChat applet wx:for loop output example
[PP-YOLOv2] Training a custom dataset
(2022牛客多校五)C-Bit Transmission(思维)
Binary tree level traversal and examples
随机推荐
[Pytorch] Study Notes (1)
A preliminary study on the use of ndk and JNI
(2022牛客多校四)H-Wall Builder II(思维)
Low-Light Image Enhancement via a Deep Hybrid Network阅读札记
(2022杭电多校三)1002-Boss Rush(状压DP+二分)
Master-slave delay reason and solution
Button Wizard Delete File Command
(2022牛客多校四)K-NIO‘s Sword(思维)
2022牛客多校六 J-Number Game(简单推理)
ArrayAccess 接口用处
PHP闭包函数 bingTo的使用
循环神经网络实现股票预测
用工具实现 Mock API 的整个流程
Modal dialog is used to implement the sign-in
PHP 类函数和对象函数
【CUDA】版本自由切换
Use Mongoose populate to implement multi-table associative storage and query, with complete code included
redis集群三主三从redis-cli
51nod 1706 最短路 + 思维
51nod 2877熟练使用tarjan的知识