Challenge - 5 Problems
Optimize and Z-ordering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of OPTIMIZE with ZORDER on a Delta table
Given a Delta table
Assume the table has multiple files and the command runs successfully.
sales with columns date, region, and amount, what will be the output of the following code snippet?spark.sql("""
OPTIMIZE sales ZORDER BY (region)
""")
Assume the table has multiple files and the command runs successfully.
Apache Spark
spark.sql(""" OPTIMIZE sales ZORDER BY (region) """)
Attempts:
2 left
💡 Hint
ZORDER BY clusters data files based on the specified column to speed up queries filtering on that column.
✗ Incorrect
OPTIMIZE with ZORDER BY reorganizes the data files to colocate rows with similar values in the specified column(s). Here, data is clustered by 'region', which improves query performance on filters using 'region'.
❓ data_output
intermediateNumber of files after OPTIMIZE without ZORDER
A Delta table
events initially has 100 small files. After running OPTIMIZE events without ZORDER, how many files will the table approximately have?Apache Spark
spark.sql("OPTIMIZE events")Attempts:
2 left
💡 Hint
OPTIMIZE merges small files to reduce file count but does not necessarily produce a single file.
✗ Incorrect
OPTIMIZE compacts many small files into fewer larger files to improve read performance. It does not always produce a single file but reduces the total number of files.
🔧 Debug
advancedIdentify the error in ZORDER syntax
What error will the following code produce?
Note: The intention is to ZORDER by the column
spark.sql("""
OPTIMIZE user_data ZORDER BY region
""")Note: The intention is to ZORDER by the column
region.Apache Spark
spark.sql(""" OPTIMIZE user_data ZORDER BY region """)
Attempts:
2 left
💡 Hint
ZORDER BY requires parentheses around the column list.
✗ Incorrect
The correct syntax requires parentheses: ZORDER BY (region). Omitting parentheses causes a syntax error.
🚀 Application
advancedChoosing columns for ZORDER to optimize query
You have a Delta table
transactions with columns user_id, transaction_date, and category. Your most frequent queries filter by user_id and category. Which ZORDER clause will best improve query performance?Attempts:
2 left
💡 Hint
ZORDER works best on columns frequently used in filters.
✗ Incorrect
ZORDER BY (user_id, category) clusters data by both columns used in filters, improving query speed for those queries.
🧠 Conceptual
expertEffect of ZORDER on data skipping and query speed
Which statement best describes how ZORDER affects data skipping and query performance in Delta Lake?
Attempts:
2 left
💡 Hint
Think about how clustering data helps skip irrelevant files during queries.
✗ Incorrect
ZORDER clusters data files by specified columns, so queries filtering on those columns can skip irrelevant files, improving speed.
