Sub topic 1
From data lakes and warehouses to the lakehouse
Prerequisites
This chapter assumes you already know the following:
- Basic SQL:
SELECT,JOIN, andGROUP BY. - Basic Python or another scripting language.
- What cloud object storage (such as Amazon S3, Azure Data Lake Storage, or Google Cloud Storage) and virtual machines are.
- The general difference between a data lake and a data warehouse. This chapter reviews it, but it does not teach it from scratch.
You do not need a Databricks account to read this chapter. The code examples later in the tutorial need one.
The problem the lakehouse addresses
Most organizations that work with data end up with two systems. Each one solves a different problem, and each one has costs.
A data warehouse stores structured data in a managed format and runs SQL on it. It gives you fast queries, transactions, and access control. The cost is that the storage format is usually proprietary, storage and compute are often priced together, and the warehouse handles unstructured data (images, logs, free text) poorly.
A data lake stores files in cheap object storage, in open formats such as Parquet, CSV, or JSON. It holds any kind of data at low cost, and many engines can read the files. The cost is that a lake is only a pile of files. It has no transactions, no enforced schema, and no built-in permissions per table. Two jobs writing at once can leave readers with half-written data.
The usual workaround is to copy data from the lake into a warehouse for reporting. That creates a second copy to keep in sync, a pipeline to maintain, and two places where permissions must be set.
The lakehouse idea
A lakehouse keeps the data in open files on cloud object storage and adds a management layer on top. That layer provides the features you expect from a warehouse:
- ACID transactions, so concurrent reads and writes see consistent data.
- Schema enforcement, so bad writes are rejected instead of silently corrupting a table.
- SQL access and table-level governance.
- Versioned history of each table.
The same files serve both analytics (SQL, dashboards) and data science or machine learning (Python, Spark). You do not copy the data between systems.
| Property | Data lake | Data warehouse | Lakehouse |
|---|---|---|---|
| Storage | Object storage, open files | Managed, often proprietary format | Object storage, open files |
| Data types | Any, including unstructured | Mostly structured | Any |
| Transactions | No | Yes | Yes |
| Schema enforcement | No | Yes | Yes |
| Typical workloads | Data science, raw storage | BI and SQL reporting | Both |
| Copies of the data | One, but unmanaged | A second copy of lake data | One |
The table is a simplification. Real products differ, and some warehouses can now query open formats. The point is the architecture: one copy of data in open storage, with a transactional layer above it.
How the lakehouse is built in practice
On Databricks, the management layer comes from two components. You will meet both in detail in later chapters.
- Delta Lake is a table format. It stores data as Parquet files plus a transaction log. The log records which files make up each version of the table, which is how transactions and history work.
- Unity Catalog is the governance layer. It organizes tables in a three-level namespace (
catalog.schema.table) and controls who can read or change them.
The diagram shows where these pieces sit relative to the storage and the engines that use them.
A first look at the code
You will run these examples properly in later chapters. Read them now to see what the lakehouse gives you.
The first example creates a managed table using the three-level name. It assumes you have permission to create objects in the main catalog.
CREATE SCHEMA IF NOT EXISTS main.tutorial;
CREATE TABLE IF NOT EXISTS main.tutorial.orders (
order_id BIGINT,
customer_id BIGINT,
amount DECIMAL(10, 2),
order_ts TIMESTAMP
);
INSERT INTO main.tutorial.orders VALUES
(1, 101, 25.00, current_timestamp()),
(2, 102, 40.50, current_timestamp()),
(3, 101, 15.25, current_timestamp());The same table is available from Python. In a notebook attached to compute, the spark session is already defined, and display renders a result as a table.
from pyspark.sql import functions as F
df = spark.table("main.tutorial.orders")
totals = (
df.groupBy("customer_id")
.agg(F.sum("amount").alias("total_amount"))
)
display(totals)An analyst using SQL and an engineer using PySpark read one table. Neither made a copy.
Because the table is a Delta table, it also keeps history. This is the feature a plain pile of Parquet files lacks:
DESCRIBE HISTORY main.tutorial.orders;
SELECT * FROM main.tutorial.orders VERSION AS OF 0;DESCRIBE HISTORY lists each operation recorded in the transaction log. VERSION AS OF 0 reads the table as it was at its first version, which here is the state right after the table was created, before the insert.
Access control comes with the table
In a lake, permissions are usually set on storage paths. In a lakehouse with Unity Catalog, you grant privileges on tables and schemas. Reading a table requires SELECT on the table and also usage privileges on its parents:
GRANT USE CATALOG ON CATALOG main TO `data-analysts`;
GRANT USE SCHEMA, SELECT ON SCHEMA main.tutorial TO `data-analysts`;The second statement grants SELECT on the schema, which applies to the tables inside it. The group needs USE CATALOG and USE SCHEMA as well. Forgetting the parent privileges is a common cause of "table not found" or permission errors even when SELECT was granted.
Common mistakes and limits
- Treating "lakehouse" as a product. It is an architecture. Databricks is one platform built around it, and the open table formats can be used elsewhere.
- Assuming the lake alone gives you transactions. Plain Parquet files in a folder do not. The transaction guarantees come from the table format, so write through Delta tables, not by dropping files into storage paths.
- Assuming everything is free of trade-offs. A lakehouse still needs table design, file maintenance, and cost control. It removes the second copy of the data. It does not remove the need to plan.
- Granting
SELECTonly. As shown above, the parent catalog and schema needUSEprivileges.
Exercises
Exercise
A team keeps raw event files in a data lake and copies cleaned data into a warehouse for dashboards. Name two problems this setup creates that a lakehouse is meant to reduce.
Show answer
Any two of the following: a second copy of the data that must be kept in sync, a copy pipeline that must be built and maintained, and permissions that must be set in two separate systems. The lakehouse serves analytics and data science from one copy of the data in open storage.
Exercise
You granted a group SELECT on main.tutorial.orders, but a user in that group still cannot query it. Which grants should you check, and why?
Show answer
Check that the group also has USE CATALOG on main and USE SCHEMA on main.tutorial. Unity Catalog requires usage privileges on the parent catalog and schema in addition to SELECT on the table.
Exercise
Which component gives a folder of Parquet files its transactions and version history on Databricks, and where is that information stored?
Show answer
Delta Lake. It stores a transaction log alongside the Parquet files. The log records which files make up each version of the table.