缓存与取消缓存表
在本课中,我们学习了可以对表进行缓存。DataFrame 通过 cache 或 persist 操作进行缓存,而表则通过 cacheTable 操作进行缓存。
已提供名为 table1 的表。
本练习是课程的一部分
Python 中的 Spark SQL 入门
练习说明
- 使用
listTables()方法列出所有表。 - 缓存
table1并确认它已被缓存。 - 取消缓存
table1并确认它已不再被缓存。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# List the tables
print("Tables:\n", spark.____.____())
# Cache table1 and Confirm that it is cached
spark.catalog.____('table1')
print("table1 is cached: ", spark.catalog.____('table1'))
# Uncache table1 and confirm that it is uncached
spark.catalog.____('table1')
print("table1 is cached: ", spark.catalog.____('table1'))