【问题标题】:What does the number meaning after the rddrdd后面的数字是什么意思
【发布时间】:2018-01-17 16:24:16
【问题描述】:

rdd后面括号里的数字是什么意思?

【问题讨论】:

    标签: apache-spark rdd


    【解决方案1】:

    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 integernextRddId 只是一个AtomicInteger):

    private[spark] def newRddId(): Int = nextRddId.getAndIncrement()
    

    生成when RDD is constructed:

    /** 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,这可以通过检查 UI 来确认:

    我们还可以看到join 在幕后创建了一些新的RDDs56)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-23
      • 2023-01-19
      • 2013-08-07
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 2020-09-08
      相关资源
      最近更新 更多