这个问题是我之前提出的一个问题(如果我在Spark中两次缓存相同的RDD会发生什么)的跟进。
当对RDD调用
下面的代码将会发生什么?
当对RDD调用
cache()
时,RDD的状态是否会改变(并且返回的RDD只是为了方便使用而是指向自身),或者会创建一个新的RDD来包装现有的RDD?下面的代码将会发生什么?
// Init
JavaRDD<String> a = ... // some initialise and calculation functions.
JavaRDD<String> b = a.cache();
JavaRDD<String> c = b.cache();
// Case 1, will 'a' be calculated twice in this case
// because it's before the cache layer:
a.saveAsTextFile(somePath);
a.saveAsTextFile(somePath);
// Case 2, will the data of the calculation of 'a'
// be cached in the memory twice in this case
// (once as 'b' and once as 'c'):
c.saveAsTextFile(somePath);