Sub topic 3
How Unity Catalog Captures Lineage Automatically
This chapter assumes you can write basic SQL and PySpark, run notebooks on a Databricks cluster or SQL warehouse, and use the catalog.schema.table namespace. You should also know what GRANT and SELECT do. The previous chapter defined lineage. This one explains how the records get created, so you can predict what will and won't appear in the lineage graph.
Lineage is a side effect of query execution
You don't turn lineage on, annotate code, or install an agent. Unity Catalog records lineage as a side effect of running a query. When Spark plans a statement, it knows which tables and columns the statement reads and which it writes. Unity Catalog extracts that information from the query plan and stores it.
This has three consequences:
- Lineage describes what actually ran, not what someone documented.
- Lineage is only as complete as the set of queries that went through Unity Catalog-aware compute.
- Lineage appears after the work runs. A table that has never been written by a captured query has no upstream edges.
What the capture path looks like
- A user, job, or pipeline submits a query or DataFrame operation.
- Compute that is governed by Unity Catalog resolves table names through the metastore.
- The query plan identifies source tables, target tables, and the columns that flow between them.
- After the run, the lineage service stores the relationship together with the entity that ran the work (a notebook, job, query, or pipeline).
- The record becomes visible in Catalog Explorer and in the lineage system tables.
What compute and code get captured
Lineage is captured for queries that read and write Unity Catalog tables, in any language Databricks supports on that compute: SQL, Python, Scala, and R. The language doesn't matter because capture works on the query plan, not on your source code.
The compute does matter. Capture requires compute that enforces Unity Catalog, meaning a cluster with an access mode that supports it (standard or dedicated) or a SQL warehouse. It also needs a Databricks Runtime version recent enough to support the feature. Column-level lineage has its own minimum runtime, so check the current documentation for your version. Serverless compute and SQL warehouses are Unity Catalog-aware by design.
The objects involved must be registered in Unity Catalog. A table that exists only as files in cloud storage, read with a raw path, has no table name to record.
Lineage is not limited to table-to-table edges. Each record also names the entity that did the work, so the graph can show these as well:
- Notebooks
- Jobs and workflow runs
- Pipelines
- SQL queries
- Dashboards
Lineage covers every workspace attached to the same metastore. A notebook in one workspace that writes a table read by a job in another workspace produces one connected graph.
A worked example
The following code creates a small pipeline. Run the SQL in a notebook or SQL editor, then run the Python in a notebook attached to Unity Catalog-enabled compute. It assumes a catalog named main and a schema named sales that you can write to.
CREATE SCHEMA IF NOT EXISTS main.sales;
CREATE OR REPLACE TABLE main.sales.orders (
order_id BIGINT,
order_date DATE,
amount DECIMAL(10, 2),
status STRING
);
INSERT INTO main.sales.orders VALUES
(1, DATE'2026-12-01', 120.00, 'complete'),
(2, DATE'2026-12-01', 80.50, 'complete'),
(3, DATE'2026-12-02', 45.00, 'cancelled');Now build a downstream table with a SQL CREATE TABLE AS SELECT:
CREATE OR REPLACE TABLE main.sales.daily_revenue AS
SELECT
order_date,
SUM(amount) AS revenue
FROM main.sales.orders
WHERE status = 'complete'
GROUP BY order_date;Build another downstream table from Python, using the DataFrame API:
from pyspark.sql import functions as F
cancelled = (
spark.table("main.sales.orders")
.where(F.col("status") == "cancelled")
.groupBy("order_date")
.agg(F.count("*").alias("cancelled_orders"))
)
cancelled.write.mode("overwrite").saveAsTable("main.sales.daily_cancellations")Both statements produce lineage even though one is SQL and one is Python. Both read main.sales.orders and write a new table.
Lineage records are not always available the instant a query finishes. Wait a few minutes, then query the system table. This query needs the privileges granted in the earlier setup, or an account that already has access to system.access.
SELECT DISTINCT
source_table_full_name,
target_table_full_name,
entity_type
FROM system.access.table_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND target_table_full_name IS NOT NULL;You should see two target tables, main.sales.daily_revenue and main.sales.daily_cancellations. The entity_type column shows the kind of entity that ran each statement, such as a notebook.
Reads and writes are separate events
Each row in system.access.table_lineage describes one observed event, and some rows have only one side filled in:
| Situation | `source_table_full_name` | `target_table_full_name` |
|---|---|---|
| Table-to-table copy or transformation | Set | Set |
| A query reads a table but writes nothing to Unity Catalog (for example, a dashboard query) | Set | Null |
| A write from a source Unity Catalog cannot name (for example, an external file or a streaming source) | Null or a path | Set |
This is why the queries in this tutorial often include IS NOT NULL filters. Without them, read-only events mix in with transformations and distort your counts.
Because events are recorded per run, the same pair of tables appears many times. Use SELECT DISTINCT or aggregate on event_time when you want the shape of the graph rather than the history.
Column lineage is captured with the same event
Column-level lineage comes from the same query plan. When Spark resolves SUM(amount) AS revenue, it knows that revenue depends on amount. Unity Catalog records that dependency in system.access.column_lineage.
Column lineage tracks data flow through expressions, not just straight copies. A column built from an aggregate, a CASE expression, or a join key still points back to its inputs. Columns that only filter rows, such as status in the WHERE clause above, are not tracked as feeding the output column in the same way. A later chapter covers how to query this table.
Common reasons lineage is missing
When someone says "the lineage graph looks empty," the cause is almost always one of these:
- The write hasn't run yet. Lineage reflects executed queries. A table created before capture was available, or only written through unsupported paths, may have no upstream edges.
- The compute was not Unity Catalog-aware. Work on a cluster without a supported access mode, or on an old runtime, produces no records.
- The data moved by path, not by table name. Reading
spark.read.parquet("s3://...")and writing it back never names a Unity Catalog table on one side. - The viewer lacks permission. Lineage exists, but the graph hides objects the user can't see. The permissions chapter covers this.
- The event is older than the retention window. Lineage is kept for a limited time, and older events age out.
- The system schema isn't enabled. If
system.accessdoesn't exist or can't be queried, an account admin needs to enable it for the metastore.
Checking capture for a single table
When you suspect a gap, ask the system table directly instead of looking at the graph. This query shows the last events that wrote a table, and which entity wrote them:
SELECT
event_time,
source_table_full_name,
entity_type,
created_by
FROM system.access.table_lineage
WHERE target_table_full_name = 'main.sales.daily_revenue'
ORDER BY event_time DESC
LIMIT 20;If this returns nothing, run the job again on Unity Catalog compute and re-check. If it returns events but the graph looks wrong, the problem is probably permissions, not capture.
Summary of the working model
- Capture is automatic and based on the query plan, so it is independent of language.
- It depends on Unity Catalog-aware compute and on tables registered in Unity Catalog.
- Each record links tables, columns, and the entity that ran the work.
- Reads and writes appear as events, and some events have only one side.
- Gaps usually come from compute, path-based access, permissions, or retention.
Exercise
A teammate's nightly job reads main.sales.orders with spark.read.parquet("s3://bucket/orders/") (the files behind that table), aggregates it, and writes the result with saveAsTable("main.sales.nightly_summary"). In system.access.table_lineage, the rows for nightly_summary have no source table. Why, and what change would fix it?
Show answer
The job reads by storage path, so the query plan never names a Unity Catalog table as the source. Only the write to main.sales.nightly_summary is recorded against a table. Changing the read to spark.table("main.sales.orders") (or SQL FROM main.sales.orders) on Unity Catalog-aware compute lets Unity Catalog record main.sales.orders as the source on future runs.
Exercise
You run a CTAS statement on a Unity Catalog SQL warehouse, and ten minutes later you see no rows for it in system.access.table_lineage. List three things you would check first.
Show answer
Check that the source and target are Unity Catalog tables (not path-only data). Check that you have permission to query system.access.table_lineage and that the system.access schema is enabled. Check your filters, such as target_table_full_name spelling and an IS NOT NULL condition on the wrong column. Also confirm the statement completed successfully, because lineage reflects executed queries.