REORG TABLE

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 11.0 and above

Reorganize a Delta Lake table by rewriting files to purge soft-deleted data, such as the column data dropped by ALTER TABLE DROP COLUMN.

Syntax

REORG TABLE table_name [WHERE predicate] APPLY (PURGE)

Note

  • REORG TABLE only rewrites files that contain soft-deleted data.

  • REORG TABLE is idempotent, meaning that if it is run twice on the same dataset, the second run has no effect.

  • After running REORG TABLE, the soft-deleted data may still exist in the old files. You can run VACUUM to physically delete the old files.

Parameters

Examples

REORG TABLE events APPLY (PURGE);

REORG TABLE events WHERE date >= '2022-01-01' APPLY (PURGE);

REORG TABLE events
  WHERE date >= current_timestamp() - INTERVAL '1' DAY
  APPLY (PURGE);