答案 0 :(得分:3)
RDD之后的数字是其标识符:
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.3.0
/_/
Using Scala version 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_151)
Type in expressions to have them evaluated.
Type :help for more information.
scala> val rdd = sc.range(0, 42)
rdd: org.apache.spark.rdd.RDD[Long] = MapPartitionsRDD[1] at range at <console>:24
scala> rdd.id
res0: Int = 1
它用于跟踪会话中的RDD,例如用于caching
:
scala> rdd.cache
res1: rdd.type = MapPartitionsRDD[1] at range at <console>:24
scala> rdd.count
res2: Long = 42
scala> sc.getPersistentRDDs
res3: scala.collection.Map[Int,org.apache.spark.rdd.RDD[_]] = Map(1 -> MapPartitionsRDD[1] at range at <console>:24)
这个数字很简单incremental integer(nextRddId
只是AtomicInteger
):
private[spark] def newRddId(): Int = nextRddId.getAndIncrement()
/** A unique ID for this RDD (within its SparkContext). */
val id: Int = sc.newRddId()
所以,如果我们遵循:
scala> val pairs1 = sc.parallelize(Seq((1, "foo")))
pairs1: org.apache.spark.rdd.RDD[(Int, String)] = ParallelCollectionRDD[2] at parallelize at <console>:24
scala> val pairs2 = sc.parallelize(Seq((1, "bar")))
pairs2: org.apache.spark.rdd.RDD[(Int, String)] = ParallelCollectionRDD[3] at parallelize at <console>:24
scala> pairs1.id
res5: Int = 2
scala> pairs2.id
res6: Int = 3
你会看到2和3,如果你执行
scala> pairs1.join(pairs2).foreach(_ => ())
您期望4,可通过检查用户界面确认:
我们还可以看到join
在封面(RDDs
和5
)下创建了一些新的6
。