การแคชและยกเลิกการแคชตาราง
ในบทเรียนนี้ เราได้เรียนรู้ว่าตารางสามารถแคชได้ โดย DataFrame จะใช้การดำเนินการ cache หรือ persist ส่วนตารางจะใช้การดำเนินการ cacheTable
มีตารางชื่อ table1 พร้อมใช้งานแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Introduction to Spark SQL in Python
คำแนะนำการฝึกหัด
- แสดงรายการตารางด้วยเมธอด
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'))