Most ETL code is a to-do list written in the wrong direction. You write how: read this, then transform that, then write there — plus the orchestration to run it in order, the retry logic for when step two fails at 3 AM, the checkpoint bookkeeping so a rerun doesn’t double-count, and the data-quality checks bolted on afterwards as a separate job nobody trusts.
Spark Declarative Pipelines flips the direction. You declare what each table should contain. The engine figures out the how: it infers the DAG from your reads, orders the work, processes incrementally, checkpoints, retries, and enforces data quality as part of the pipeline itself. If that sounds like Delta Live Tables — it is. DLT grew up, got renamed, and moved into Apache Spark itself.
The naming story, briefly
What you knew as Delta Live Tables (DLT) is now Lakeflow Declarative Pipelines on Databricks, and its core was donated to Apache Spark as Spark Declarative Pipelines (SDP), available through pyspark.pipelines starting in Spark 4.1. Your old import dlt code keeps working — Databricks is explicit that migration is optional — but new code uses the new module:
from pyspark import pipelines as dp # the modern API; `import dlt` still works
One honest split to know up front: the open-source core covers dataset definitions (tables, materialized views, views). A few APIs are Databricks Runtime extensions — dp.create_auto_cdc_flow, @dp.expect, @dp.temporary_view — and don’t exist in OSS Spark. Code written against the OSS module runs unmodified on Databricks; the reverse isn’t always true. I’ll flag which is which as we go.
The core idea: the DAG is inferred, not written
Here’s the whole mental model in one pipeline:
from pyspark import pipelines as dp
from pyspark.sql import functions as F
@dp.table(comment="Raw orders as they arrive")
def bronze_orders():
return (
spark.readStream.format("cloudFiles")
.option("cloudFiles.format", "json")
.load("/volumes/prod/landing/orders")
)
@dp.table(comment="Validated, deduplicated orders")
def silver_orders():
return (
spark.readStream.table("bronze_orders") # ← this read IS the dependency edge
.withColumn("order_date", F.to_date("order_ts"))
.dropDuplicates(["order_id"])
)
@dp.materialized_view(comment="Daily revenue by region")
def gold_daily_revenue():
return (
spark.read.table("silver_orders") # ← and this one
.groupBy("order_date", "region")
.agg(F.sum("amount").alias("revenue"))
)
Nowhere in that file does it say “run bronze first, then silver, then gold.” The engine sees silver_orders reading bronze_orders and draws the edge itself. Reorder the functions, split them across files, add a fourth dataset in the middle — the DAG comes out the same, because the DAG was never in your code. It was in your reads. That’s what “declarative” means here: the dependencies are a property of the data flow, not of your orchestration script.
This is also why the modern read style matters. The current API reads upstream datasets with plain Spark — spark.read.table(...) for batch, spark.readStream.table(...) for streaming — and the engine tracks the lineage from ordinary DataFrame operations. The old dp.read() / dlt.read() helpers still work but are deprecated; don’t write new code with them.
Three dataset types, and the 2026 split that matters
There are exactly three kinds of datasets, and picking the right one is the main design decision in a declarative pipeline:
- Streaming table (
@dp.tableon a streaming DataFrame): append-only, incremental. Each input record is processed once. This is your ingestion layer and your incremental transforms. - Materialized view (
@dp.materialized_view): the result of a query, kept up to date — recomputed incrementally when the engine can, fully when it must. This is where aggregations and joins live, because it’s the type that stays correct when upstream data changes. - View (
@dp.temporary_view/@dp.view): evaluated on demand, never persisted. Scratch space inside the pipeline.
The subtle rule worth internalizing: streaming tables don’t recompute on late changes; materialized views do. An append-only event log is a streaming table. A gold KPI that must reflect a corrected dimension is a materialized view. Get this backwards and your “fixed” upstream data silently never reaches gold.
And here’s the 2026 API change that trips up everyone porting old DLT tutorials: the old @dlt.table conflated streaming and batch — the dataset type was a property of the query. The new API splits declared intent from query shape: @dp.table means “I intend a streaming table,” @dp.materialized_view means “I intend a materialized view.” Write a batch query under @dp.table and you get the wrong dataset type with no error. When in doubt, be explicit.
Data quality as code: expectations
The part that sold me. Data quality stops being a separate Great Expectations job that runs after the damage is done, and becomes decorators on the dataset itself — evaluated on every run, with metrics recorded per rule:
@dp.table(comment="Validated orders")
@dp.expect_or_drop("valid_amount", "amount > 0") # bad row? gone, pipeline continues
@dp.expect_or_fail("has_key", "order_id IS NOT NULL") # bad row? halt the whole update
@dp.expect("sane_region", "region IN ('NA','EU','APAC')") # bad row? keep it, record the metric
def silver_orders():
return spark.readStream.table("bronze_orders")...
Three verbs, three philosophies: warn keeps the row and records that the rule was violated (metrics, not gates); drop removes violating rows and keeps the pipeline moving; fail aborts the update — nothing downstream gets the bad data. There’s also @dp.expect_all(...) and friends for attaching a dict of rules at once, and a SQL spelling (CONSTRAINT valid_amount EXPECT (amount > 0) ON VIOLATION DROP ROW).
Dropped rows shouldn’t vanish into the void. The standard pattern routes them to a quarantine table so someone can inspect and replay them:
@dp.table(name="quarantine_orders")
def quarantine_orders():
return (
spark.readStream.table("bronze_orders")
.filter("order_id IS NULL OR amount <= 0")
)
Try it live — this is exactly what the lab below simulates:
Two things to notice while you play with it. First, a fail violation doesn’t just skip rows — it aborts the update, so gold goes stale rather than wrong. That’s the correct default for a broken primary key: stale dashboards get noticed, wrong dashboards get believed. Second, the execution order never changes no matter how you scramble the code — try the “write functions in reverse” toggle. The DAG comes from reads, remember?
(And yes: @dp.expect is one of the Databricks Runtime extensions — it doesn’t exist in OSS Spark 4.1. If you’re on the open-source engine, data-quality gating is on you.)
CDC without the merge-statement archaeology
Change data capture is where imperative pipelines go to die — hand-rolled MERGE statements with watermark logic, late-arriving updates, and delete handling. The declarative version is two calls (Databricks extension, not in OSS):
# Target must exist first: an empty streaming table
dp.create_streaming_table(name="dim_customers")
dp.create_auto_cdc_flow(
target="dim_customers",
source="stg_customer_cdc", # a table/view name, never a DataFrame
keys=["customer_id"],
sequence_by="updated_at",
stored_as_scd_type=2, # integer 2 = Type 2, string "1" = Type 1
)
stored_as_scd_type=2 keeps full history with __START_AT / __END_AT columns maintained by the engine. Type 1 ("1", note the string) overwrites in place. The source is a name, not a DataFrame — another instance of the same philosophy: you point at data, the engine owns the mechanics.
What the engine does while you’re not looking
It’s worth enumerating, because “the engine handles it” is doing a lot of quiet work:
- Ordering and parallelism — from the inferred DAG, including running independent branches concurrently.
- Incremental processing — streaming tables process each record once via checkpoints; materialized views refresh incrementally when possible.
- Retries and recovery — a failed task retries with its checkpoint intact; reruns don’t double-process.
- Observability — every run writes to an event log: row counts per dataset, expectation metrics per rule, durations. The metrics the
@dp.expectwarn rules record land here too. - Pipeline modes — triggered (run once, shut down — the batch-shaped choice) vs continuous (always on, lowest latency).
The gotchas, from the official docs
Three rules that bite everyone exactly once:
- Your dataset functions run multiple times — during planning, not just execution. They must contain only the code needed to define the DataFrame. No branching on data, no side effects.
- Never call actions inside them. No
collect(),count(),toPandas(),save(), orsaveAsTable(). The function must return an unexecuted DataFrame; the engine decides when it runs. (This is the same laziness my Spark DataFrame post is about, enforced with an error.) - One default target schema per pipeline. If you publish to both
silverandgoldschemas, schema-qualify the dataset names (name="silver.orders") — otherwise everything lands in the default schema and you’ll wonder where your tables went.
Why this matters beyond Databricks
The strategic bit: declarative pipelines are now an open Apache Spark standard, not a vendor feature. The patterns — declare datasets, infer the DAG from reads, gate quality with expectations, let the engine own incremental state — are portable knowledge. Whether you run on Databricks’ Lakeflow, OSS Spark 4.1, or something else entirely in three years, “declare the table, not the job” is the durable idea. Orchestrators tell tasks when to run; declarative pipelines let the data tell the engine what exists. Once you’ve felt the difference — no 3 AM “step two failed” pages because there are no numbered steps — it’s hard to go back.