Sub topic 3
How Unity Catalog Captures Lineage Automatically
This chapter assumes you know basic SQL, can run notebooks and SQL warehouses in Databricks, and understand the three-level namespace (catalog.schema.table). You do not need to configure anything to get lineage. You do need to know what triggers it, so you can tell why an expected link is missing.
The working model
Unity Catalog records lineage at runtime. When a query or job runs on compute that Unity Catalog governs, the engine knows which tables and columns it read and which it wrote. It saves that information as lineage events. Nobody annotates the code or registers a pipeline.
Lineage capture does not depend on how you write the code. It works for these entry points:
- SQL run in a notebook or on a SQL warehouse.
- Python, Scala, and R code that uses DataFrames or Spark SQL.
- Lakeflow Declarative Pipelines (formerly Delta Live Tables) and Databricks Jobs.
- Dashboards and other Databricks entities that read tables.
Lineage is attached to the entity that did the work, such as a notebook, job, pipeline, or query. That is why the lineage tables report an entity type.
A worked example
Suppose you run this in a notebook attached to Unity Catalog compute:
CREATE OR REPLACE TABLE main.sales.daily_revenue AS
SELECT
order_date,
SUM(amount) AS revenue
FROM main.sales.orders
GROUP BY order_date;The statement reads main.sales.orders and writes main.sales.daily_revenue. Unity Catalog records:
- A table-level link from
orderstodaily_revenue. - Column-level links:
orders.order_datefeedsdaily_revenue.order_date, andorders.amountfeedsdaily_revenue.revenue. - The entity that ran the statement, here the notebook.
After a short delay you can see this link in the lineage tables. Lineage is not instant, so a query you ran seconds ago may not appear yet.
What counts as a link
A link needs both a read and a write in the same operation. A plain SELECT that only displays results can still be recorded as a read, but it creates no downstream table.
Column lineage follows expressions. In the example, revenue comes from amount through an aggregate. The link is still recorded, because the column was used to compute the output.
Common reasons a link is missing
Most gaps come from a small set of causes.
| Symptom | Likely cause |
|---|---|
| No lineage for a table at all | The work ran on compute that does not use Unity Catalog, or used file paths instead of table names |
| Link appears in one place but not another | The reader lacks privileges on the objects, so the graph hides them |
| Recent job not shown | Lineage events arrive with a delay |
| Link older than expected is gone | The event is past the retention window |
Reading data by path, for example with spark.read.load("s3://bucket/path"), may record path-based lineage rather than a table link. Reading by table name is the reliable pattern.
# Reads and writes by table name, so lineage is recorded
orders = spark.table("main.sales.orders")
daily = (
orders.groupBy("order_date")
.sum("amount")
.withColumnRenamed("sum(amount)", "revenue")
)
daily.write.mode("overwrite").saveAsTable("main.sales.daily_revenue")Checking capture yourself
After running the example, confirm the link with a query against the lineage system table. The caller needs the privileges shown in the system tables chapter.
SELECT DISTINCT
source_table_full_name,
target_table_full_name,
entity_type
FROM system.access.table_lineage
WHERE target_table_full_name = 'main.sales.daily_revenue'
AND source_table_full_name IS NOT NULL;If the row is missing, check the compute type, then whether you used table names, then wait a few minutes and retry.
Exercise
A teammate's job reads main.sales.orders using a storage path (spark.read.load("s3://bucket/orders")) and writes main.sales.summary. You expect a table-to-table link but do not find one. What is the most likely cause, and what change fixes it?
Show answer
The read used a file path instead of the table name, so Unity Catalog does not record a table-level link from main.sales.orders. Change the job to read with spark.table("main.sales.orders") (or SQL FROM main.sales.orders) on Unity Catalog compute, then rerun it and check again after a short delay.