Sub topic 6
Querying system.access.table_lineage
This chapter shows how to read table lineage with SQL. It assumes you know basic SQL (SELECT, WHERE, DISTINCT), the catalog.schema.table namespace, and how GRANT works. It also assumes you know that Unity Catalog captures lineage automatically as queries and jobs run.
What the table holds
system.access.table_lineage is a system table. It stores one row for each read or write event that Unity Catalog recorded between tables. Each row names a source table, a target table, the time of the event, and the kind of entity that did the work, such as a notebook, job, or pipeline.
These columns matter most for the queries below:
| Column | Meaning |
|---|---|
| `source_table_full_name` | Table that was read. Can be null when the event is a write with no table source. |
| `target_table_full_name` | Table that was written. Can be null when the event is a read with no table target. |
| `source_type` | Type of the source, such as a table or a path. |
| `entity_type` | Type of the entity that ran the work, such as a notebook or job. |
| `event_time` | When the event happened. |
The null values are the most common source of confusion. A row that reads a table into a dashboard has a source but no target. A row that writes a table from files has a target but no table source. You filter on IS NOT NULL to keep only table-to-table edges.
Grant access first
Ordinary users cannot read system tables by default. A metastore admin or a user with the right privileges grants access. Grant only what the group needs.
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 SELECT ON TABLE system.access.audit TO `data-governance`;This gives the group data-governance read access to lineage and audit data and nothing else in the system catalog.
Find upstream sources
To see what feeds a table, filter on the target. This query lists the tables that were read to produce main.sales.daily_revenue.
SELECT DISTINCT
source_table_full_name,
source_type,
entity_type,
event_time
FROM system.access.table_lineage
WHERE target_table_full_name = 'main.sales.daily_revenue'
AND source_table_full_name IS NOT NULL
ORDER BY event_time DESC
LIMIT 100;The IS NOT NULL filter removes writes that have no table source. ORDER BY event_time DESC puts the newest events first, and LIMIT keeps the result small. The entity_type column tells you whether a notebook, job, or other entity did the work, so you know where to look next.
Find downstream consumers
To see what depends on a table, swap the filter. This query finds every table written from main.sales.orders.
SELECT DISTINCT
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;This is the starting point for judging the impact of a change. If you plan to rename a column or drop main.sales.orders, the result lists the tables you must check first.
How the two directions relate
Upstream and downstream queries use the same table. Only the filtered column changes.
Common errors
- Empty result. The table may not have run since lineage capture applied, or the name is wrong. Use the full three-level name in lowercase, as Unity Catalog stores it.
- Permission error. The
systemcatalog needsUSE CATALOGandUSE SCHEMAas well asSELECTon the table. - Duplicate-looking rows. The same edge appears once per event. Use
DISTINCT, or group and takemax(event_time)to see the latest run. - Missing edges. Lineage has limits, which a later chapter covers. Do not treat an empty result as proof that no dependency exists.
Exercise
You plan to drop the table main.sales.orders. Which query tells you which tables are written from it, and which filter removes events that have no table target?
Show answer
Query system.access.tablelineage with WHERE sourcetablefullname = 'main.sales.orders' AND targettablefull_name IS NOT NULL. The IS NOT NULL condition removes events with no table target, such as reads into a dashboard, so only table-to-table edges remain.
Exercise
A query for upstream sources of a table returns no rows, although you know a job writes to it. Name two causes you should check.
Show answer
The table name may be wrong, since it must be the full three-level name. Or the lineage capture may have missed the write because of a lineage limitation. A missing USE CATALOG or USE SCHEMA grant on the system catalog would cause an error, not an empty result.