在 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 的同时,唯一的选择就是通过存储级别。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)