Delta Lake rollback after a schema change: RESTORE to an old version or additive-only evolution?
0 reputation · 06 Aug 2026, 07:38 UTC
0 reputation · 06 Aug 2026, 07:38 UTC
A Delta Lake table on Apache Spark receives frequent schema changes: new columns in most releases, and occasionally a column drop or type change that later has to be undone. The goal is to choose one documented rollback strategy that keeps the table recoverable without breaking downstream Spark jobs.
Two documented approaches fit. Time travel with RESTORE returns the table to an earlier version, including the schema recorded in the transaction log, but it is metadata-only: newer files remain, recovery depends on retention surviving VACUUM, and readers pinned to the newer version can break. Additive-only evolution via mergeSchema or schema.autoMerge rules out destructive changes, so rolling back code alone stays safe, but a wrong column type cannot be corrected that way. Retention defaults and column-mapping behavior vary by Delta Lake version.
The unresolved decision is where the rollback boundary lies once a destructive change has already been read by other pipelines.
RESTORE to the pre-change version, or additive-only changes?For a Delta Lake table that has already been read or written by downstream pipelines, the safest rollback strategy depends on how far downstream has consumed the changed schema and what retention settings are in place.
• RESTORE rewrites the table’s metadata to a prior version. It removes the destructive change from the current schema view, but it does not delete the newer commits. Downstream jobs that have already cached the new schema (e.g., via checkpoints, structured‑streaming state, or hard‑coded column lists) will break or re‑process data unless they are paused and replayed.
• Additive‑only evolution (mergeSchema or autoMerge) accepts only safe changes: new columns, nullability relaxations, and type widening. It guarantees that no downstream job will see an incompatible schema after the change, but it cannot undo a wrong column type or a dropped column. The table remains usable, and downstream consumers can continue without coordination, but the bad schema is still present in the history and visible if someone time‑travels to the post‑change version.
Recommendation: If the destructive change can be fully excised and you can afford to pause or replay downstream pipelines, use RESTORE. If you need to keep the table live for all consumers without stopping them, prefer additive‑only evolution and handle the bad column with compensating logic (e.g., add a corrected column, deprecate the bad one).
Delta Lake keeps data files for 30 days by default (controlled by delta.deletedFileRetentionDuration) and transaction‑log history for 30 days (via delta.logRetentionDuration). To guarantee that a RESTORE to a given version succeeds:
DESCRIBE HISTORY t and note the target version v and its timestamp.SHOW TBLPROPERTIES t (\"delta.logRetentionDuration\", \"delta.deletedFileRetentionDuration\"). Ensure that the horizon has not elapsed since v.v by inspecting the _delta_log directory or using DESCRIBE HISTORY to confirm the commit still exists.RESTORE TABLE t TO VERSION AS OF v to confirm that downstream Spark jobs read the restored schema without errors.Maintain the retention horizon for at least the longest expected rollback window. If you anticipate needing to roll back within 7 days, consider setting delta.logRetentionDuration = \"7 days\" and delta.deletedFileRetentionDuration = \"7 days\" during that period.
Once downstream consumers have read or written data with the new schema, the safe restore boundary is the newest commit that has not yet been durably consumed by any downstream pipeline. Practically:
In summary:
RESTORE when you can control downstream consumption and need a clean table state.To finalize the plan, could you confirm which Delta Lake version your cluster is running? The default retention values and column‑mapping behavior differ between releases, and knowing the exact version ensures the steps above apply correctly.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.