Databricks Data Engineer Professional Question 58
Single answerYou are designing a data lakehouse architecture for a retail company. They store transactional sales data in a Delta table with billions of rows and frequently query it by region and date. What is the best approach to partition the Delta table to optimize query performance?
- A
Partition the table by both
regionanddateto create a hierarchical directory structure. - B
Partition the table by
regiononly, as it is a categorical column with a manageable number of unique values. - C
Partition the table by
dateonly, as it is a column frequently queried in time-based filters. - D
Do not partition the table at all and rely on Delta Lake's data skipping and indexing capabilities.
Show answer and explanation
Correct answer: C
Explanation
Partitioning is a critical strategy for optimizing query performance on large datasets in Delta Lake. Selecting appropriate partition columns involves balancing the column's cardinality and query patterns. In this scenario, partitioning by date improves query efficiency because it is a common filter and likely has lower cardinality compared to region. Partitioning by both columns or not partitioning at all would result in inefficiencies either due to small file proliferation or excessive scanning. Partitioning only by region is suboptimal since it does not align with the primary query pattern.
- A. Incorrect.
Partitioning by both
regionanddatecan lead to an excessively large number of small files if both columns have high cardinality, making it inefficient. - B. Incorrect.
Partitioning by
regiononly is not optimal, as queries ondatewould require scanning all partitions for the required date range, leading to increased query time. - C. Correct.
Partitioning by
dateonly is the best choice becausedateis frequently filtered in queries, and it is typically a column with lower cardinality compared toregion. This ensures better query performance while avoiding the creation of too many small files. - D. Incorrect.
Not partitioning at all would result in poor query performance for large datasets since filters on
dateandregionwould require scanning the entire table.