Start here
In "Storage Layers & File Formats" you met Parquet files and the small-files problem. A folder of Parquet files is cheap. But it is only a folder of files.
Plain files have no transactions. A transaction is a change that happens fully or not at all.
A job that fails halfway leaves half-written files. Two jobs that write at the same time can break each other.
Delta Lake fixes this. It keeps a small log next to the Parquet files.
The log says which files make up the table. The log and its rules are called a table format.
A lakehouse joins three parts.
- Open files, such as Parquet, on cheap storage.
- A table format, such as Delta Lake, that adds transactions.
- Engines, such as Spark, that read and write the table.
In "The Warehouse Platform: Storage, Compute & Loading" you saw time travel in Snowflake. Delta Lake gives you time travel on files that you own.
This chapter uses open-source Delta Lake 3.x. You turn it on once, when you build the Spark session. You also need the delta-spark package.
from pyspark.sql import SparkSession
spark = (SparkSession.builder
.config("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension")
.config("spark.sql.catalog.spark_catalog",
"org.apache.spark.sql.delta.catalog.DeltaCatalog")
.getOrCreate())The data is the shop again. The table orders starts with six rows.
| order_id | customer_id | status | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | paid | 40.00 | 2026-01-03 |
| 102 | 1 | paid | 25.00 | 2026-01-10 |
| 103 | 2 | refunded | 60.00 | 2026-01-11 |
| 104 | 3 | paid | 15.50 | 2026-01-15 |
| 105 | 3 | pending | NULL | 2026-01-20 |
| 106 | 4 | paid | 80.00 | 2026-01-21 |
You will change this one Delta table, one version at a time. Here is the whole story.
| Version | What happens | Rows after |
|---|---|---|
| 0 | Create the table from orders 101 to 106. | 6 |
| 1 | Append orders 220 and 221. | 8 |
| 2 | Update order 105: it was paid, 22.00. | 8 |
| 3 | A wrong delete removes customer 3. | 6 |
| 4 | Restore version 2. | 8 |
| 5 | Append order 222, with a new column. | 9 |
| 6 | MERGE: update 104, delete 221, insert 223. | 9 |
| 7 | OPTIMIZE joins small files. | 9 |
| 8 | Turn on the change feed. | 9 |
| 9 | Update order 223. | 9 |
