ACID transactions on Parquet,
with version history.
Delta Lake is an open table format: it stores the rows in Parquet and each change in a transaction log. This gives the table consistent reads, versions to go back in time, MERGE, UPDATE, and DELETE, and a single table for batch and streaming. See what happens in a commit, how a read rebuilds the table, and what happens when two writers write at the same time.
An open table format makes a set of data files work like an SQL table, which several engines read and write.
Delta Lake is one of the TDP table formats, alongside Apache Iceberg, and keeps the state of each table in a transaction log.
The log is the table
The table describes itself
Which files make up the table, with which schema and which partitions, is written in the log, stored alongside the data. The table can be read without a separate metastore and copied with ordinary file system tools.
One version per commit
All or nothing
Each commit is a new file in the log, with the next version number. The version appears whole or does not exist, and readers never see a half-finished write.
No locks
Multiple writers at the same time
With optimistic concurrency, each writer checks, before committing, whether another one changed the same files. If there is a conflict, the write fails, and the table stays intact.
On this page
- Watch a commit happen
- Architecture
- The name of a commit
- From the log to the table
- Two writers at the same time
- A self-describing table
- Why Delta Lake
- In the TDP editions
Watch a commit happen
A DELETE in Spark and a read in Trino, on the same table. Press Play or step through. Underlined names lead to the Glossary.
1 Spark reads the current version
A DELETE reaches Spark. Before writing, Spark reads the table's latest version from the log and identifies which data files have rows that meet the condition: those are the ones that must be rewritten.
In the Glossary: Current version · Original file
- Spark reads the current version. A DELETE reaches Spark. Before writing, Spark reads the table's latest version from the log and identifies which data files have rows that meet the condition: those are the ones that must be rewritten.
- The copy is written. Spark writes a new copy of each of those files, now without the deleted rows, with a new and unique name. The original file stays where it is, because no data file is overwritten, and for now no reader sees the copy.
- Check before committing. Spark checks whether another writer has committed, since the version it read, any change that conflicts with its own. With no conflict, it proceeds to the commit. With a conflict, the write fails with a concurrent modification exception, and the table stays as it was.
- The commit: a new file in the log. Spark writes to the log the JSON file of the next version, with the commit's actions: remove for the original file, add for the copy, and commitInfo with the operation performed. A log entry is never overwritten, and only one writer creates each version: with this file, the new version takes effect in full.
- Trino reads the new version. Trino rebuilds the table from the log and reads only the files listed as added, among them the copy. The original file becomes a tombstone: it stays in storage for reads that still use the previous version, until VACUUM deletes it after the retention period.
Architecture
One directory per table: the data files and, next to them, the transaction log.
What the figure shows:
- The transaction log lives in the
_delta_logsubdirectory, inside the table directory. In the figure, it is the top band, with the checkpoint and the commits. - The
_last_checkpointfile points to the most recent checkpoint. - The checkpoint, in Parquet, consolidates the complete state of the table at one version. In the figure, the version 42 one holds the entire state up to that point: the
protocolandmetaDataactions and theaddactions of the files that are present.metaDatacarries the schema and the partitions, andprotocolsays what a client needs to know to use the table. - The commits come after the checkpoint: each one is a JSON file with one action per line, and
commitInforecords the operation. In the figure, they are versions 43, 44, and 45: 43 adds one file, 44 removes one file and adds its rewritten copy, and 45 adds another. - The data files, in Parquet, live in the table directory, next to the log. In the figure, they are the files that are present and the rewritten copy.
- The
addandremoveactions add and remove data files. In the figure, the green arrows connect eachaddto the file it references, and the dashed arrow connects theremoveto the removed file. - The tombstone is the file removed by version 44: it stays in storage until VACUUM.
In Apache Iceberg, the catalog holds a pointer to the current metadata file, and the commit is the swap of that pointer. In Delta Lake, the current version is the highest-numbered one in the log, next to the data, and the commit is the creation of that version's file. In both formats, the change is published at once, and readers see a whole version.
The name of a commit
Each table version is a file with a predictable address inside the table directory.
Click each part of the path.
Table directory
Everything that makes up the table lives here: the data files, at the root or in subdirectories, and the transaction log. With the metadata alongside the data, the table can be copied or moved with ordinary file system tools.
See in the Glossarymytable— Table directory- Everything that makes up the table lives here: the data files, at the root or in subdirectories, and the transaction log. With the metadata alongside the data, the table can be copied or moved with ordinary file system tools.
_delta_log— Transaction log- Holds the commits, in JSON, the checkpoints, in Parquet, and the _last_checkpoint file. Since the name starts with an underscore, the directory is not mistaken for a data file subdirectory.
00000000000000000043.json— Commit- One table version. The name is the version number, padded with leading zeros. The content is JSON, with one action per line, applied on top of the previous version. The checkpoint of this same version would be called 00000000000000000043.checkpoint.parquet.
The leading zeros make the alphabetical order of the files match the order of the versions.
That is why, from the version of the checkpoint indicated in _last_checkpoint, a reader finds the newest commits without listing the entire log.
From the log to the table
Four commits, one checkpoint, and one question: which files make up the table at each version?
1 Version 0: the table is born
The first commit brings the protocol action, with the minimum reader and writer versions, the metaData action, with the schema, the partition columns, and the configuration, and an add for the first data file. At version 0, the table is f1.
- Version 0: the table is born. The first commit brings the protocol action, with the minimum reader and writer versions, the metaData action, with the schema, the partition columns, and the configuration, and an add for the first data file. At version 0, the table is f1.
- Version 1: an INSERT. An insert writes f2 and commits with add f2. The existing files do not change. At version 1, the table is f1 and f2.
- Version 2: a DELETE rewrites f1. The delete writes f3, a copy of f1 without the deleted rows, and commits with remove f1 and add f3. At version 2, the table is f2 and f3; f1 stays in storage as a tombstone, until the retention expires.
- A checkpoint consolidates version 2. The version 2 checkpoint stores, in Parquet, the result of applying commits 0, 1, and 2: protocol, metaData, add f2, add f3, and the remove of f1, kept while it is a tombstone. The _last_checkpoint file now points to it.
- Version 3: one more file. A new insert writes f4 and commits with add f4. The checkpoint does not change: it still describes version 2.
- A read of the latest version. The reader opens _last_checkpoint, loads the version 2 checkpoint, and applies only commit 3. For each file, the most recent reference wins, and the result is f2, f3, and f4: only these files are read. The remove of f1 does not enter the read. It serves VACUUM.
- Time travel to version 1. A query with VERSION AS OF 1 cannot use a checkpoint newer than the requested version. The reader applies commits 0 and 1 and arrives at f1 and f2, the table as it was. This only works while those commits and the f1 file remain retained.
A table's state at a version is its snapshot: the protocol, the metadata, the files present, and the tombstones.
Time travel reaches a version as long as its log and data files are retained: log cleanup, after checkpoints, and VACUUM, on the data files, define that limit. See Versions and time travel.
Two writers at the same time
Both read the same version. The result depends on whether they touched the same files.
With optimistic concurrency, nobody locks the table.
At commit time, each writer compares its change with what others have committed since the version it read. If the changes do not overlap, its change enters as a new version, in the table's serial order. If they overlap, the write fails with a concurrent modification exception, and the table stays as it was.
| Concurrent operation | INSERT | UPDATE, DELETE, MERGE INTO | Compaction |
|---|---|---|---|
| INSERT | No conflict | ||
| UPDATE, DELETE, MERGE INTO | May conflict | May conflict | |
| Compaction | No conflict | May conflict | May conflict |
Compaction, here, is the rewriting of files recorded with dataChange equal to false, which only reorganizes existing data.
Where a conflict is possible, it only happens if the two operations act on the same set of files. An UPDATE with date > '2010-01-01' and a DELETE with date < '2010-01-01' may touch the same files in a table not partitioned by date. With the table partitioned by date, the sets separate and the conflict disappears.
When the conflict happens, the exception name gives the reason, such as ConcurrentAppendException, when another operation added files to the partition that was read, or ConcurrentDeleteReadException, when another operation deleted a file that was read.
A self-describing table
Besides the files, the log stores the schema, the compatibility rules, and the history of each change.
The metaData action carries the schema, the partition columns, and the table configuration, and the most recent one is the one that holds. Each write goes through schema validation: a column the table does not have or a type different from the column's makes the write fail. Columns can be added or reordered through DDL or in the write itself, with schema evolution enabled.
The protocol action says what a client must implement to read or write the table: the minimum reader and writer versions and the table features in use, enabled table by table. A newer version of Delta Lake always reads and writes tables from earlier versions, and some features require all of the table's clients to be upgraded. See Protocol.
The commitInfo action records, in each commit, the operation and who ran it. DESCRIBE HISTORY returns this history, from the most recent commit to the oldest, with the metrics of each write, and free text can accompany the commit, through the userMetadata option.
They adjust the behavior of each table and live in the metaData action itself. A table can, for example, accept only appends, with no record deletion or value changes, and have defined how long the history is kept and how long a removed file is stored before it can be deleted.
VERSION AS OF and TIMESTAMP AS OF read the table at an earlier version, and RESTORE returns the table to an earlier state, by version or by timestamp. Both depend on the log and the files of that version still being retained. See Time travel.
Why Delta Lake
Isolation
Always-consistent reads
ACID transactions with serializable isolation: readers use a consistent snapshot of the table, even with writes happening at the same time.
Scale
Distributed metadata
Spark's distributed processing handles the metadata of petabyte-scale tables, with billions of files, and a query can be planned on a single machine or in parallel.
Batch and streaming
One table for both
The same table is a batch table and a streaming source and sink. Whoever follows the log knows what came in during a period, which makes incremental processing efficient.
Updates
MERGE, UPDATE, and DELETE
Merge, update, and delete operations serve cases such as change data capture (CDC), slowly changing dimensions (SCD), and streaming upserts.
Versions
Going back in time
Data versioning makes it possible to undo changes, keep complete audit trails, and reproduce machine learning experiments.
Connectors
Several engines, the same table
Spark, Flink, Hive, Trino, and other engines read and write Delta tables through their own connectors.
Delta Lake is an independent open source project and, since 2019, has been part of the Delta Lake Project, a sub-project of the Linux Foundation Projects. The code is distributed under the Apache 2.0 license.
In the TDP editions
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 3.3.0 | TDP Datacenter components |
| TDP Kubernetes | 4.0.1 · chart tdp-deltalake 3.0.3 | Configuration in TDP Kubernetes |
In TDP Datacenter
In TDP Datacenter, Delta Lake tables are queried by Trino, and format support lives in the services' configuration, in Ambari.
The Delta Lake connector can be enabled in use.deltalake, in the connectors-properties configuration. The deltalake catalog uses the delta_lake connector and the Hive Metastore address, in hive.metastore.uri. The connector reads the transaction log directly and therefore notices when other systems change the data. See Trino.
The creation of a Delta Lake data service in OpenMetadata can be enabled in deltalake.enabled, with the integration turned on in integration.enabled, in the openmetadata_integration configuration. See OpenMetadata.
In TDP Kubernetes
In TDP Kubernetes, the tdp-deltalake chart delivers scheduled maintenance jobs for Delta Lake tables, with Spark as the runtime.
VACUUM, OPTIMIZE, OPTIMIZE Z-ORDER, and DESCRIBE HISTORY, in maintenance.jobs.*. Each job is enabled in enabled, has its schedule in schedule, and processes the tables listed in tables or, with the list empty, all the Delta tables registered in the Hive Metastore. OPTIMIZE Z-ORDER processes only the listed tables, with the columns of each one. OPTIMIZE Z-ORDER and DESCRIBE HISTORY come disabled. The role of each job is in Scheduled maintenance.
Each job runs Spark in its own pod, with the image defined in maintenance.spark.image.*, which already includes the Delta Lake and S3A libraries. The jobs do not need a Spark cluster. The Spark cluster that the chart can bring up, in spark.enabled, comes disabled and is not used by the jobs. The Delta Lake SQL extensions and catalog go in maintenance.spark.config, in the spark.sql.extensions and spark.sql.catalog.spark_catalog properties.
S3-compatible, through the S3A endpoint in maintenance.spark.config. The credentials arrive through the s3-credentials Secret, with the access-key and secret-key keys.
Spark, with the optional tdp-spark.deltaLake.enabled block, which adds the Delta Lake SQL extension and catalog. The Spark image includes the Delta Lake libraries. Jupyter also reads and writes the tables maintained by the chart. See Where Spark and Trino find the tables.
Next steps
TDP Kubernetes
Delta Lake Configuration
Maintenance jobs, schedules, commands, and resources in the chart.
TDP Datacenter
Trino
The Delta Lake connector and the other connectors that can be enabled in the Ambari Trino service.
Concept
Lakehouse
Delta Lake and Iceberg on S3 storage, with transactions, versions, and scheduled maintenance.
Table format
Apache Iceberg
The other TDP table format, which can coexist with Delta Lake in the same environment.
Sources
Delta Lake - Transaction Log Protocol
Delta Lake - Concurrency control
Delta Lake - Table batch reads and writes
Delta Lake - Table deletes, updates, and merges
Delta Lake - Table utility commands