2016-07-21 68 views
2

我是新來的Apache星火,我創建了幾個RDD的和DataFrames,緩存的他們,現在我想用下面星火列表中的所有緩存RDD名字

rddName.unpersist() 

命令unpersist一些人,但我可以」不要忘記他們的名字。我用sc.getPersistentRDDs,但輸出不包含名稱。我還使用瀏覽器查看緩存的rdds,但又沒有名稱信息。我錯過了什麼嗎?

+0

eliasah,對不起,我以爲我已經接受你的答案.. – fanbondi

回答

4

@ Dikei的回答實際上是正確的,但我相信你正在尋找的是sc.getPersistentRDDs

scala> val rdd1 = sc.makeRDD(1 to 100) 
# rdd1: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[0] at makeRDD at <console>:27 

scala> val rdd2 = sc.makeRDD(10 to 1000) 
# rdd2: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[1] at makeRDD at <console>:27 

scala> rdd2.cache.setName("rdd_2") 
# res0: rdd2.type = rdd_2 ParallelCollectionRDD[1] at makeRDD at <console>:27 

scala> sc.getPersistentRDDs 
# res1: scala.collection.Map[Int,org.apache.spark.rdd.RDD[_]] = Map(1 -> rdd_2 ParallelCollectionRDD[1] at makeRDD at <console>:27) 

scala> rdd1.cache.setName("foo") 
# res2: rdd1.type = foo ParallelCollectionRDD[0] at makeRDD at <console>:27 

scala> sc.getPersistentRDDs 
# res3: scala.collection.Map[Int,org.apache.spark.rdd.RDD[_]] = Map(1 -> rdd_2 ParallelCollectionRDD[1] at makeRDD at <console>:27, 0 -> foo ParallelCollectionRDD[0] at makeRDD at <console>:27) 

現在讓我們添加另一個RDD並將它命名爲好:

scala> rdd3.setName("bar") 
# res4: rdd3.type = bar ParallelCollectionRDD[2] at makeRDD at <console>:27 

scala> sc.getPersistentRDDs 
# res5: scala.collection.Map[Int,org.apache.spark.rdd.RDD[_]] = Map(1 -> rdd_2 ParallelCollectionRDD[1] at makeRDD at <console>:27, 0 -> foo ParallelCollectionRDD[0] at makeRDD at <console>:27) 

我們注意到,實際上它不會被持續。

0

rrdName變量沒有特殊含義。這只是對RDD的參考。例如,在下面的代碼

val rrdName: RDD[Something] 
val name2 = rrdName 

name2rrdName是兩個引用指向相同的RDD。撥打name2.unpersist與撥打rrdName.unpersist相同。

如果您想要unpersist RDD,您必須手動保存對它的引用。