Sub topic 1
What a Declarative Pipeline Is and Why It Exists
Prerequisites
This chapter assumes you know the following:
- Basic SQL (SELECT, JOIN, GROUP BY).
- Basic Python and PySpark DataFrames, for the Python examples in later chapters.
- Databricks workspaces, notebooks, and Unity Catalog catalogs and schemas.
- The difference between batch and streaming data.
- Delta Lake tables.
The problem with hand-built orchestration
A typical data flow has several steps: ingest files, clean them, aggregate them. Without a framework, you write one notebook per step and chain them in a Databricks job. You then have to handle everything around the queries yourself:
- Task order, so each step runs after the one it reads from.
- Checkpoints, so streaming steps know what they have already processed.
- Retries after failures.
- Cluster sizing and lifecycle.
- Data quality checks.
Most of this code says how to run the flow. It says little about what the data should look like.
The declarative model
Lakeflow Declarative Pipelines (formerly Delta Live Tables, or DLT) reverse this. You declare each dataset and the query that produces it. Databricks works out the rest: the execution order, the compute, the checkpoints, the retries, and the incremental processing.
A pipeline is a Databricks object that holds these dataset definitions. It has source code files, a target catalog and schema, and a compute setting. Each update of the pipeline reads your definitions, builds a dependency graph, and runs the datasets in a valid order.
There are two main dataset types:
| Dataset type | Best for | How it processes data |
|---|---|---|
| Streaming table | Append-style data such as files or events | Processes only new input on each update |
| Materialized view | Transformed or aggregated results | Keeps the query result up to date, refreshing incrementally where possible |
Later chapters cover each type in detail.
A first example
This SQL declares a streaming table that ingests new JSON files from a Unity Catalog volume:
CREATE OR REFRESH STREAMING TABLE orders_bronze
AS SELECT *
FROM STREAM read_files(
'/Volumes/main/demo/raw/orders/',
format => 'json'
);The statement describes a result, not a procedure. It does not create a checkpoint location or set a trigger. It does not say where in the job this step belongs. The pipeline handles those details.
A second dataset can read from the first by name, and the pipeline infers the dependency:
CREATE OR REFRESH MATERIALIZED VIEW daily_revenue
AS SELECT
date(order_ts) AS order_date,
SUM(amount) AS revenue
FROM orders_silver
GROUP BY date(order_ts);Here daily_revenue reads orders_silver, so the pipeline always updates orders_silver first.
What you gain
- Less orchestration code. You write no task dependencies by hand.
- Incremental processing by default. Streaming tables read only new data.
- Built-in data quality. Expectations, covered in a later chapter, are part of the dataset definition.
- Observability. Every update records events you can query.
Common errors
- Treating a pipeline as a script. Files in a pipeline define datasets. They are not run top to bottom, so statement order does not set execution order.
- Running pipeline code in a regular notebook. Pipeline syntax such as
CREATE OR REFRESH STREAMING TABLEis meant to run through a pipeline update. Attach the file to a pipeline instead. - Writing to a dataset from outside the pipeline. The pipeline owns its datasets. Manual writes or edits can conflict with updates.
- Expecting free-form side effects. A dataset query should return a result. Avoid logic that depends on side effects, because the pipeline may run it more than once.
Exercise
In your own words, why does the pipeline not need you to specify the order in which orders_silver and daily_revenue run?
Show answer
The query for daily_revenue reads orders_silver. The pipeline infers this dependency from the queries and builds a dependency graph, so it updates orders_silver before daily_revenue without any explicit ordering.