使用给定存储级别缓存指定的内存中表。 默认MEMORY_AND_DISK。
Syntax
cacheTable(tableName: str, storageLevel: StorageLevel = None)
参数
| 参数 | 类型 | Description |
|---|---|---|
tableName |
str | 要获取的表的名称。 可以使用目录名称进行限定。 |
storageLevel |
StorageLevel自选 |
要为持久性设置的存储级别。 |
注释
缓存的数据在群集上的所有 Spark 会话之间共享。
示例
_ = spark.sql("DROP TABLE IF EXISTS tbl1")
_ = spark.sql("CREATE TABLE tbl1 (name STRING, age INT) USING parquet")
spark.catalog.cacheTable("tbl1")
# or
spark.catalog.cacheTable("tbl1", StorageLevel.OFF_HEAP)
# Throw an analysis exception when the table does not exist.
spark.catalog.cacheTable("not_existing_table")
# Traceback (most recent call last):
# ...
# AnalysisException: ...
# Using the fully qualified name for the table.
spark.catalog.cacheTable("spark_catalog.default.tbl1")
spark.catalog.uncacheTable("tbl1")
_ = spark.sql("DROP TABLE tbl1")