Data Transformation and Modeling
Medallion and Delta fundamentals
Bronze preserves raw data, silver holds conformed and deduplicated entities, gold holds business aggregates. Delta Lake provides ACID transactions, schema enforcement (with mergeSchema opt-in), time travel, MERGE, deletion vectors, and liquid clustering. Column statistics enable data skipping; OPTIMIZE compacts small files; Z-ORDER co-locates related values; VACUUM removes unreferenced files (default 7-day retention, and time travel past that horizon stops working).
Modeling moves
- Deduplicate before merging using
ROW_NUMBER()over the business key ordered by ingestion timestamp. - SCD Type 1 overwrites attributes; SCD Type 2 inserts a new version and closes the prior row with
valid_toandis_current. In pipelines useAPPLY CHANGES INTOwith a sequencing column. - Partition only large tables (roughly >1 TB) on low-cardinality columns; prefer liquid clustering over partitioning plus Z-ORDER for new tables because clustering keys can change without rewriting history.
- Never partition on high-cardinality columns - you get small files and slow listing.
Traps
MERGEerroring on duplicate source keys; fix the source, not the merge.- Using
INSERT OVERWRITEwhere late-arriving data must be preserved. - Writing many tiny files from a streaming job without compaction.
- Assuming
VACUUMdeletes rows from history - it deletes files, and older queries then fail.
Worked example
To keep a silver customers table current: stage the batch, dedupe by customer_id, then MERGE on customer_id with a matched-update branch setting updated_at = current_timestamp() and a not-matched insert branch, followed by a nightly OPTIMIZE.