spark源码阅读笔记RDD(二)RDD子类基本方法和信息

RDD子类



 
 

// =======================================================================
// Methods that should be implemented by subclasses of RDD
// =======================================================================

/**
 * :: DeveloperApi ::
 * Implemented by subclasses to compute a given partition.
 */
@DeveloperApi
def compute(split: Partition, context: TaskContext): Iterator[T]


/**
  * compute:用来计算RDD的subclass的partition
  *  Scala中的Iterator,可用来依次取下一个数据
  *  它有一个特点,叫TraversableOnce,就像单行道,只能向前走,不能回头
  */


/**
 * Implemented by subclasses to return the set of partitions in this RDD. This method will only
 * be called once, so it is safe to implement a time-consuming computation in it.
 *得到子类的  partition和index的信息
 * The partitions in this array must satisfy the following property:
 *   `rdd.partitions.zipWithIndex.forall { case (partition, index) => partition.index == index }`
 */
protected def getPartitions: Array[Partition]

/**
 * Implemented by subclasses to return how this RDD depends on parent RDDs. This method will only
  * 得到父RDD的信息
 * be called once, so it is safe to implement a time-consuming computation in it.
 */
protected def getDependencies: Seq[Dependency[_]] = deps

/**
 * Optionally overridden by subclasses to specify placement preferences.由子类重写指定位置偏好。
 */
protected def getPreferredLocations(split: Partition): Seq[String] = Nil

/** Optionally overridden by subclasses to specify how they are partitioned. */

@transient val partitioner: Option[Partitioner] = None

// =======================================================================
// Methods and fields available on all RDDs
// =======================================================================

/** The SparkContext that created this RDD. 每个RDD都可以包含创建时候关于环境的信息*/
def sparkContext: SparkContext = sc

/** A unique ID for this RDD (within its SparkContext). */
val id: Int = sc.newRddId()

/** A friendly name for this RDD */
@transient var name: String = null

/** Assign a name to this RDD */
def setName(_name: String): this.type = {
  name = _name
  this
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值