A scenario for a data engineer · Senior and up
The MERGE takes two hours
Patch · Your teammate
Tuesday, 08:50
A nightly MERGE loads one day of events into a Delta table that holds three years, matching on event id alone. It reads almost every file in the table to look for matches.
What do you do?
Tap the one you would do. The answer opens below.
Show the best callThe best call
Add the event date to the match condition, so only the files for that day are searched.
The MERGE skips nearly the whole table and finishes in minutes.
Why
A MERGE has to find the rows that match. If the condition names only the key, any file might hold a match. Adding what you know, such as the dates the batch covers, lets Delta skip files that cannot match. It works best when the table is clustered or partitioned by that column.
Read it in the Databricks docs (opens in a new tab)The other two
- Works, at a price. Run it on a larger cluster with Photon.
- Faster tonight, for more money, and slower again each month as the table grows.
- A poor call. Switch to a plain append and remove duplicates in the reports.
- The load is fast. The table now holds duplicates, and every reader has to deal with them.
The words in this scenario
- MERGE.
- One statement that compares new rows with a table by a key: rows that match are updated or deleted, rows that do not are inserted. In the docs (opens in a new tab)
Go deeper on brickster.ai
- Delta Lake: what changed recentlyNews, releases, videos and questions on it, gathered daily.
- Drill Spark in PracticeShort questions with the reason after each answer.
More scenarios
- The dashboard takes four minutes · data engineer
- One task has been running for an hour · data engineer
- The cleaning step takes most of the run · data engineer
- All 47 scenarios
Had one like this at work? Send it to us: the best tickets come from real incidents.
Checked against the Databricks documentation on . brickster.ai is independent and is not affiliated with Databricks.