Skip to the page
Tecyfy

Databricks interview question · easy

Ron was performing an UPDATE operation on a large Delta table. He then realized he made a mistake. How can he easily revert the update without manually reconstructing the previous state?

The short answerRon can undo it with Delta Lake time travel: find the table version just before his UPDATE in the table history, then run RESTORE TABLE to that version.

The full answer

Ron can undo it with Delta Lake time travel: find the table version just before his UPDATE in the table history, then run RESTORE TABLE to that version.

1. Find the version before the mistake

DESCRIBE HISTORY my_table;

The history lists every commit, newest first, with its version number, timestamp, operation (UPDATE, MERGE, WRITE and so on), who ran it and its metrics. Ron looks for his UPDATE and takes the version just before it, say version 41.

2. Check the old data first (optional but wise)

SELECT count(*) FROM my_table VERSION AS OF 41;
SELECT * FROM my_table TIMESTAMP AS OF '2026-10-16 09:00:00' LIMIT 10;

In Python: spark.read.option("versionAsOf", 41).table("my_table"). On Databricks the short form my_table@v41 also works. Reading an old version never changes the table.

3. Restore

RESTORE TABLE my_table TO VERSION AS OF 41;
-- or
RESTORE TABLE my_table TO TIMESTAMP AS OF '2026-10-16 09:00:00';

In Python: DeltaTable.forName(spark, "my_table").restoreToVersion(41).

What RESTORE does. It does not delete history. It writes a new version whose contents equal version 41, so the bad update is still in the history and the restore itself can be undone. It needs MODIFY permission on the table, and it is quick because it mostly changes which files the log points to, rather than rewriting data.

Things to watch

  • Retention. Time travel needs the old data files. VACUUM removes files older than the table's retention (7 days by default), and log entries are kept 30 days by default. If the update is older than that, or a vacuum with short retention ran, the version may be gone.
  • Writes after the mistake. Restoring to version 41 also removes anything other jobs wrote after it. If others wrote since, it may be safer to fix the rows with a MERGE from the old version instead.
  • Streaming readers. A restore counts as a data change, so streams reading the table may process the restored rows again and create duplicates downstream.

Preventing it next time. Run risky updates on a test copy first (a shallow clone, CREATE TABLE t_test SHALLOW CLONE t, is instant), check the number of affected rows the UPDATE reports before moving on, and keep write permission on production tables with jobs rather than people.

Last updated 16 October 2026

Sources

Where each fact comes from

  1. 1Work with table history
  2. 2Clone a table on Databricks

Asked next