QuestionQ194

VerifiedProductionizing Data Pipelines

A data engineer needs to optimize the data layout and query performance for an e-commerce transactions Delta table. The table is partitioned by "purchase_date" a date column which helps with time-based queries but does not optimize searches on user statistics "customer_id", a high-cardinality column.

The table is usually queried with filters on "customer_id" within specific date ranges, but since this data is spread across multiple files in each partition, it results in full partition scans and increased runtime and costs.

How should the data engineer optimize the Data Layout for efficient reads?

Explanation

Delta Lake liquid clustering cannot be enabled on a table that still has partitioning defined — running ALTER TABLE ... CLUSTER BY against a partitioned table raises an error, so keeping the existing "purchase_date" partitioning while adding clustering is not a valid configuration. The supported migration path converts the table so it clusters on both the high-cardinality "customer_id" and the frequently filtered "purchase_date" column, letting Delta co-locate and prune files for combined predicate queries without the small-file and full-scan problems that directory-based partitioning causes on high-cardinality fields.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!