What happens at VACUUM with delta tables?

Viewed 138

When we run VACUUM command, does it go through each parquet file and remove older versions of each record or does it retain all the parquet files even id it has one record with the latest version? What about compaction? Is this any different?

2 Answers

Vacuum and Compaction go through the _delta_log/ folder in your Delta Lake Table and identify the files that are still being referenced.

Vacuum deletes all unreferenced files. Compaction reads in the referenced files and writes your new partitions back to the table, unreferencing the existing files.

Think of a single version of a Delta Lake table as a set of parquet data files. Every version adds an entry (about files added and removed) to the transaction log (under _delta_log directory).

VACUUM

VACUUM allows defining what number of hours to retain (using RETAIN number HOURS clause). That gives Delta Lake the versions to delete (up to the number HOURS). These versions are "translated" into a series of parquet files (remember one single parquet file belongs to a single version until it is deleted that may take a couple of versions).

This translation gives the files to be deleted.

Compaction

Compaction is basically an optimization (and is usually triggered by OPTIMIZE command or a combination of repartition, dataChange disabled and overwrite).

This is nothing else as another version of a delta table (but this time data is not changed so other transactions can happily be all committed).

The explanation about VACUUM above applies here.

Related