Complete the code to optimize a Delta table named 'sales'.
spark.sql("OPTIMIZE [1]")
The OPTIMIZE command is used to compact files in the specified Delta table. Here, we optimize the 'sales' table.
Complete the code to optimize the 'sales' table with Z-Ordering on the 'customer_id' column.
spark.sql("OPTIMIZE sales ZORDER BY ([1])")
Z-Ordering helps to colocate related information in the same set of files. Here, we optimize the 'sales' table by Z-Ordering on 'customer_id'.
Fix the error in the code to optimize the 'sales' table with Z-Ordering on 'region'.
spark.sql("OPTIMIZE sales ZORDER BY [1]")
The ZORDER BY clause requires parentheses around the column list. So, '(region)' is correct.
Fill both blanks to create a Python function that optimizes a Delta table with Z-Ordering on a given column.
def optimize_table(table_name, column): spark.sql(f"OPTIMIZE [1] ZORDER BY ([2])")
Use the variables directly inside the f-string without quotes to pass the table name and column dynamically.
Fill all three blanks to create a dictionary comprehension that maps each table name to its optimized Z-Ordering column.
optimize_map = { [1]: [2] for [3] in tables }This comprehension iterates over each table dict in 'tables', using 'table' as the variable. The key is the table name, and the value is the Z-Ordering column.
