什么是RDDS?
RDDS即Resilient distributed datasets(弹性分布式数据集)。
Spark中,所有计算都是通过RDDs的创建,转换,操作完成的。
一个RDD是一个不可改变的分布式集合对象。
Driver Program
包含程序的main方法,RDDs的定义和操作。
它管理很多节点,我们称之为excetor。
Spark Context
Driver Program是通过SparkContext对象访问spark。
SparkContext对象代表和一个集群的连接。
在Shell中SparkContext自动创建好了,就是sc。
分片
每个分片包含一部分数据,partitions可在集群的不同节点上计算。
分片是spark并行执行的单元,spark是顺序的,并行的处理分片。
RDDs的创建方法
1
把一个存在的集合传给Sprakcontext的parallelize()方法,用于测试
var rdd = sc.parallelize(Array(1,2,2,4),4)
其中,第一个参数表示待并行化处理的集合,第二个参数:分片的个数。
2
加载外部数据集
val rddText = sc.textFile('helloSpark.txt')