Sub topic 1
What Delta Lake is and where it fits in Databricks
Prerequisites
This chapter assumes you know:
- Basic SQL (SELECT, INSERT, WHERE).
- Basic PySpark DataFrames.
- How to open a Databricks notebook and attach compute.
- What tables, schemas and data types are.
You don't need to know how Delta works internally. The next chapter covers that.
What Delta Lake is
Delta Lake is an open-source storage layer that adds table features to files in cloud object storage. A Delta table is a directory with two parts:
- Data files in Parquet format. Parquet is a columnar file format that Spark reads efficiently.
- A transaction log in a
_delta_logsubdirectory. It records every change made to the table.
Plain Parquet files are only files. They have no record of which files belong to a table, and a failed job can leave half-written output behind. Delta Lake adds a log that defines what the table contains at any moment. That log gives you:
- ACID transactions. A write either commits fully or not at all.
- Schema enforcement. Writes that don't match the table's columns are rejected.
- Row-level changes with
UPDATE,DELETEandMERGE. - Table history, so you can query or restore earlier versions.
Where it fits in Databricks
Databricks describes its platform as a lakehouse. It combines the cheap, open storage of a data lake with the reliability of a data warehouse. Delta Lake is the storage layer that makes this work.
Delta is the default table format on Databricks. A CREATE TABLE statement without a USING clause produces a Delta table. Other Databricks features build on it, including Unity Catalog governance, streaming reads and writes, and Lakeflow pipelines.
Tables are addressed with a three-level name in Unity Catalog: catalog.schema.table. Unity Catalog is the Databricks governance layer. It controls access and tracks metadata for your tables. This tutorial uses names like main.sales.orders.
Confirming a table is Delta
You can inspect any table with DESCRIBE DETAIL. It reports the format, storage location and file count.
DESCRIBE DETAIL main.sales.orders;Check the format column for delta. The location column shows the storage path that holds the data files and the _delta_log directory. You will create this table in a later chapter.
Common mistakes
- Treating a Delta table as a folder of Parquet files. Don't edit or delete its files directly. Changes made outside Delta commands bypass the log and can corrupt the table.
- Assuming that "Delta" and "Databricks" are the same thing. Delta Lake is open source. Other engines can read Delta tables, though some Databricks features are specific to the platform.
- Reading the data files without the log. A Parquet reader pointed at the directory may see files that the table no longer includes, such as rows that were updated or deleted.
What comes next
The following chapters follow the order in which you will use Delta. They cover how the log works, managed and external tables, creating tables, and then changing data safely. Everything builds on the structure described here: Parquet files plus a log.
Exercise
A teammate copies the Parquet files out of a Delta table's directory and reads them with a plain Parquet reader. The row counts don't match what SELECT COUNT(*) returns on the table. What is the most likely cause?
Show answer
The table has had updates or deletes. Delta writes new Parquet files and records in the transaction log which old files are no longer part of the table. Those old files stay in storage until cleanup. A plain Parquet reader ignores the log, so it reads old and current files together and gets a different count.