在 Spark 中,可以显式设置 RDD 和 Dataframe 的存储级别,但是否可以更改默认存储级别?如果可以,如何实现?如果不是,为什么不可能?
到处都有类似的问题,但答案只是指解决方案是显式设置存储级别,无需进一步解释。
最佳答案
我建议看看 CacheManager.scala#cacheQuery(..) 。方法定义和文档如下所示-
/**
* Caches the data produced by the logical representation of the given [[Dataset]].
* Unlike `RDD.cache()`, the default storage level is set to be `MEMORY_AND_DISK` because
* recomputing the in-memory columnar representation of the underlying table is expensive.
*/
def cacheQuery(
query: Dataset[_],
tableName: Option[String] = None,
storageLevel: StorageLevel = MEMORY_AND_DISK): Unit = writeLock {
...
}
}
这里,如果您观察到 Spark 内部没有使用任何配置来获取默认存储级别,而是其默认值硬编码在源本身中。
因为没有可用于覆盖默认行为的配置。唯一的选择就是在保留数据帧/RDD 的同时传递存储级别。
关于apache-spark - Spark 是否可以设置默认存储级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63192797/