Spark RDD特点

RDD:Resilient Distributed Dataset

A Resilient Distributed Dataset(RDD), the basic abstraction in Spark. Represents an immutable, partitioned collection of elements that can be operated on in parallel.

RDD特点:

  • A list of partitions —— 一系列的分片:比如说64M一片;类似于Hadoop中的split
  • A function for computing each split —— 在每个分片上都有一个函数去迭代/执行/计算它
  • A list of dependencies on other RDDs —— 一系列的依赖:RDDa转换为RDDb,RDDb转换为RDDc,那么RDDc就依赖于RDDb,RDDb就依赖于RDDa
  • Optionally, a Partitioner for key-value RDDs(e.g. to say that the RDD is hash-partitioned) —— 对于key-value的RDD可指定一个partitioner,告诉它如何分片;常用的有hash,range
  • Optionally, a list of perferred location(s) to compute each split on(e.g. block locations for an HDFS file) —— 要运行的计算/执行最好在哪(几)个机器上运行。数据的本地性。
    为什么会有哪几个?
    比如:hadoop默认有3个位置,或者spark cache到内存是可能通过StorageLevel设置了多个副本,所以一个partition可能返回多个最佳位置

前三个特点对应于Lineage,后两个对应于Optimized execution

对于如上的5个特点,对应于RDD中的5个方法

getPartitions                         the set of partitions in this RDD

compute                               compute a given partition

getDependencies                 return how this RDD depends on parent RDDs

partitioner                             specify how they are partitioned

getPreferredLocations          specify placement preferences

参考资料:http://www.it610.com/article/1916210.htm

猜你喜欢

转载自agilestyle.iteye.com/blog/2294284