Sub topic 7
Tracing individual columns with system.access.column_lineage
This chapter assumes you can write SELECT queries with filters and joins. It also assumes you know the catalog.schema.table namespace and have read access to the system catalog, as covered earlier in this tutorial. Here you will query column-level lineage to answer questions that table-level lineage cannot.
Why column lineage exists
Table lineage tells you that main.sales.daily_revenue was built from main.sales.orders. It does not tell you which columns were involved. That gap matters in two common situations:
- Change impact: You plan to rename or redefine
orders.amount. Table lineage lists every consumer oforders, including ones that never touchamount. Column lineage narrows the list to the real dependents. - Sensitive data: A column such as
customer_emailis tagged as personal data. You need to know every table that received a copy or a derivation of it.
Unity Catalog records column lineage at runtime, alongside table lineage, when a supported workload reads and writes tables. The records are exposed in system.access.column_lineage.
The shape of the table
Each row is one observed edge: a source column feeding a target column during one run of a notebook, job, query, or pipeline. The columns you will use most are:
| Column | Meaning |
|---|---|
| `source_table_full_name` | Three-level name of the table that was read |
| `source_column_name` | Column that was read |
| `target_table_full_name` | Three-level name of the table that was written |
| `target_column_name` | Column that received the data |
| `source_type`, `target_type` | Kind of object, such as a table, view, or path |
| `entity_type`, `entity_id` | The notebook, job, pipeline, or query that did the work |
| `entity_run_id` | The specific run of that entity |
| `created_by` | The identity that ran the workload |
| `event_time`, `event_date` | When the edge was observed |
Some rows have a null source or target table name. These usually describe a read from or write to a storage path instead of a table. Filter with IS NOT NULL when you only want table-to-table edges.
Always filter on event_date. It lets the engine skip data, and it keeps the answer tied to a time window you can name.
Granting access
The table is not readable by ordinary users. A metastore admin or a user with sufficient rights on the system catalog grants access to a governance group. This is the same grant block used in the earlier system-table chapters. The relevant lines are:
GRANT USE CATALOG ON CATALOG system TO `data-governance`;
GRANT USE SCHEMA ON SCHEMA system.access TO `data-governance`;
GRANT SELECT ON TABLE system.access.table_lineage TO `data-governance`;
GRANT SELECT ON TABLE system.access.column_lineage TO `data-governance`;Grant to a group, not to individuals. Grant only the tables the group needs.
Going upstream: where does a column come from?
This query asks which source columns feed revenue in main.sales.daily_revenue.
SELECT DISTINCT
source_table_full_name,
source_column_name,
target_column_name
FROM system.access.column_lineage
WHERE target_table_full_name = 'main.sales.daily_revenue'
AND target_column_name = 'revenue';If revenue is computed as SUM(quantity * unit_price), expect two rows: one for quantity and one for unit_price. Both are listed because both contribute to the value. Column lineage records dependency, not the formula. To see the formula, open the job or notebook that appears in entity_type and entity_id.
To add the time window and the workload that produced each edge, extend the query:
SELECT DISTINCT
source_table_full_name,
source_column_name,
entity_type,
entity_id,
created_by,
event_time
FROM system.access.column_lineage
WHERE target_table_full_name = 'main.sales.daily_revenue'
AND target_column_name = 'revenue'
AND source_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS
ORDER BY event_time DESC;Because the same job usually runs repeatedly, you will see many rows that differ only in event_time. Use DISTINCT without event_time for a list of dependencies, and keep event_time when you need to know how recently each edge was seen.
Going downstream: what depends on this column?
Reverse the filter to start from a source column and find everything derived from it.
SELECT DISTINCT
target_table_full_name,
target_column_name,
entity_type
FROM system.access.column_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND source_column_name = 'amount'
AND target_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS;Compare this with the table-level downstream query from the previous chapter. The table-level result may list ten consumers of orders. This result lists only those that actually carried amount forward. That shorter list is your review list for a change to amount.
Walking more than one hop
The system table stores direct edges only. One row says "A fed B", not "A eventually fed D". To follow a chain, join the table to itself. This query walks two hops upstream from revenue:
WITH hop1 AS (
SELECT DISTINCT
source_table_full_name,
source_column_name
FROM system.access.column_lineage
WHERE target_table_full_name = 'main.sales.daily_revenue'
AND target_column_name = 'revenue'
AND source_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS
)
SELECT DISTINCT
h.source_table_full_name AS hop1_table,
h.source_column_name AS hop1_column,
c.source_table_full_name AS hop2_table,
c.source_column_name AS hop2_column
FROM hop1 AS h
LEFT JOIN system.access.column_lineage AS c
ON c.target_table_full_name = h.source_table_full_name
AND c.target_column_name = h.source_column_name
AND c.source_table_full_name IS NOT NULL
AND c.event_date >= current_date() - INTERVAL 90 DAYS;The LEFT JOIN keeps first-hop columns that have no recorded parent, for example columns loaded from files. Those rows show nulls in the hop2_ columns. For deeper chains, repeat the join or use a recursive common table expression if your SQL warehouse supports one. Stop at a fixed depth, because a pipeline that writes back into its own source can create cycles.
Gotchas and edge cases
- Capture depends on the workload. Lineage is recorded for queries run through supported compute, such as SQL warehouses and clusters with Unity Catalog access. A write from an unsupported tool leaves no edge, and the column looks as if it has no downstream use. Absence of a row is not proof of absence of a dependency.
- Only observed runs appear. An edge exists only if a workload actually ran in the retention window. A monthly job that last ran 13 months ago is gone from the table.
- Renames break the chain. After you rename a column, edges recorded under the old name stay under the old name. Search for both names when you investigate history.
- Dynamic and wildcard SQL.
SELECT *expands to individual columns at run time, so edges are recorded per column. If an upstream table gains a column later, new edges appear only after the next run. - Joins and filters. A column used only in a join key or a
WHEREclause may not appear as a source for target columns, because no target value is copied from it. Treat column lineage as value flow. For code-level dependencies, inspect the job source. - Row volume. A busy pipeline produces many rows per day. Always set
event_datebounds, and useDISTINCTorGROUP BYbefore you count anything.
Retention
Lineage system tables keep data for a rolling window, documented as one year at the time of writing. Check the current Databricks documentation, since retention can change. If you need longer history for audits, copy the rows you need into a Delta table you own on a schedule, and apply your own access controls to that copy.
Exercise
The orders table has columns order_id, amount, and customer_id. You plan to change how amount is calculated. Write a query that lists tables and columns that received data from main.sales.orders.amount in the last 30 days, and explain why this list can be shorter than the table-level downstream list.
Show answer
Use SELECT DISTINCT target_table_full_name, target_column_name FROM system.access.column_lineage WHERE source_table_full_name = 'main.sales.orders' AND source_column_name = 'amount' AND target_table_full_name IS NOT NULL AND event_date >= current_date() - INTERVAL 30 DAYS;. The list can be shorter because table lineage reports every table built from any column of orders, such as ones using only customer_id. Column lineage reports only the edges where amount was the source column.
Exercise
Your two-hop query returns a first-hop column with null values in the hop2_ columns. Give two possible reasons.
Show answer
The first-hop column may be loaded from files or another path, so no source table is recorded for it. The job that wrote it may be outside the retention window, or it may have run on compute that does not capture lineage. Either way the null means no recorded parent, not that the column has none.