Skip to content

A scenario for a data engineer · Senior and up

Which region was this customer in back then?

Query · Analytics
Wednesday, 15:45

Sales wants revenue by the region each customer was in at the time of the sale. The customers Delta table holds only the current region: every change overwrites the old one. They will ask again next year.

What do you do?

Tap the one you would do. The answer opens below.

Show the best call

Keep history in the table from now on: a new row for each change, with the dates it was valid.

From today, every past region can be joined to the sale by date. Next year's question is one query.

Why

Time travel is for recent mistakes: by default old data files can be removed after seven days and the log is kept for thirty. History that must last belongs in the data, as type 2 rows with a start and an end. AUTO CDC keeps them for you with STORED AS SCD TYPE 2.

Read it in the Databricks docs (opens in a new tab)

The other two

Works, at a price. Save a full copy of the table every night.
The history is there from today. Queries must pick the right copy, and storage grows by a full table a day.
A poor call. Leave the table as it is. Next year, read it as it was with time travel.
Next year the query fails. A table keeps old versions for days or weeks, not for a year.

The words in this scenario

RESTORE and table history.
A Delta table keeps a history of its versions. A query can read an earlier version, and RESTORE puts the table back to one. In the docs (opens in a new tab)

Go deeper on brickster.ai

More 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.