Spark的“persist”或“cache”的作用域`

2024-10-01 07:18:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我对RDD在Spark中的范围感到困惑。在

根据this thread

Whether an RDD is cached or not is part of the mutable state of the RDD object. If you call rdd.cache it will be marked for caching from then on. It does not matter what scope you access it from.

因此,如果我定义了一个函数,其中创建了一个新的rdd,例如(python代码)

# there is an rdd called "otherRdd" outside the function

def myFun(args):
    ...
    newRdd = otherRdd.map(some_function)
    newRdd.persist()
    ...

newRdd是否存在于全局命名空间中?或者它只在myFun的环境中可见?在

如果它只在myFun的环境中可见,那么在myFun完成执行之后,它将自动unpersistnewRdd?在


Tags: ofthefromyouan环境isnot
1条回答
网友
1楼 · 发布于 2024-10-01 07:18:28

是的,当RDD被垃圾回收时,它是未持久化的。所以在myFun之外,newRdd是未持久化的(假设您没有返回它也没有派生rdd),您还可以检查这个answer。在

相关问题 更多 >