Dropping and recreating Delta tables results in a DeltaVersionsNotContiguousException error

Instead of dropping and recreating Delta tables, use the CREATE OR REPLACE command.

Written by manisha.jena

Last published at: September 12th, 2024

Problem

If you frequently drop and recreate Delta tables, you may encounter a DeltaVersionsNotContiguousException error.

com.databricks.sql.transaction.tahoe.DeltaVersionsNotContiguousException: Versions (0, 1, 31) are not contiguous.

Cause

This can happen for two reasons. 

  • Files have been manually removed from the Delta log, which disrupts the sequence of versions. For example, if you have a job that loads data into a Delta table and data are deleted and reloaded for each run.
  • You drop and recreate Delta tables. This practice can lead to inconsistencies in the Delta log, as the transactions are not guaranteed to be ACID-compliant.

Solution

Instead of dropping and recreating Delta tables, use the CREATE OR REPLACE command. For more information, please review the CREATE TABLE [USING] (AWSAzureGCP) documentation.

To avoid the problem generally, follow best practices for dropping Delta tables. For more information, please review the Best practices for dropping a managed Delta Lake table knowledge base article. 

If the error persists, Databricks support can assist with repairing the Delta table and ensuring Delta log integrity.

Was this article helpful?