Sub topic 6
Querying system.access.table_lineage
This chapter assumes you can write SQL with joins and aggregates, can run queries from a notebook or SQL warehouse, and know the catalog.schema.table naming. It also assumes you know how Unity Catalog captures lineage at runtime and what a system table is. Your account admin must have enabled the access system schema, and you need read access to it (see the next section).
What the table contains
system.access.table_lineage is a system table. Each row is a lineage event: something read from a source, wrote to a target, or both. Rows are produced when workloads run, so the table is a history of observed data movement. It is not a catalog of declared dependencies.
The columns you use most often:
| Column | Meaning |
|---|---|
| `source_table_full_name` | Three-level name of the table that was read. Null if the event has no source table. |
| `source_type` | Kind of source, such as `TABLE`, `VIEW`, or `PATH`. |
| `source_path` | Storage path, when the source was a path rather than a table. |
| `target_table_full_name` | Three-level name of the table that was written. Null if the event is a read only. |
| `target_type` | Kind of target, such as `TABLE` or `VIEW`. |
| `entity_type` | What ran the work, such as `NOTEBOOK`, `JOB`, `PIPELINE`, or `DBSQL_QUERY`. |
| `entity_id` and `entity_run_id` | Identifier of that notebook, job, or pipeline, and of the specific run. |
| `created_by` | The user or service principal that triggered the work. |
| `event_time` and `event_date` | When the event happened. `event_date` is the date part. |
Your workspace may show additional columns, such as workspace and metastore identifiers. Run DESCRIBE TABLE system.access.table_lineage to see the exact schema in your account.
The null rules matter because they decide which filter you write:
- A row with a source and a target means "this target was produced from this source".
- A row with a source and no target means the table was only read, for example by a dashboard or ad hoc query.
- A row with a target and no source means the target was written, but no Unity Catalog table was read. The input may have been a file path or a literal value.
Granting access
Ordinary users cannot read system tables by default. A metastore admin or a user with the right privileges grants access to a specific group. Grant only the tables that group needs, not the whole system catalog.
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`;The last grant gives the group the audit table as well, which later chapters use. If a group only needs lineage, leave that line out.
Question 1: what feeds this table?
To list the upstream tables of a target, filter on the target and require a non-null source:
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 write-only rows. Without it, you get rows where the source is empty, which look like noise.
Because the same job may run every hour, one source can appear hundreds of times. To get one row per source and see when it was last used, aggregate instead of using DISTINCT:
SELECT
source_table_full_name,
source_type,
entity_type,
max(event_time) AS last_seen,
count(*) AS event_count
FROM system.access.table_lineage
WHERE target_table_full_name = 'main.sales.daily_revenue'
AND source_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 30 DAYS
GROUP BY source_table_full_name, source_type, entity_type
ORDER BY last_seen DESC;The event_date filter limits how much data is scanned. It also answers a more useful question: which sources are still feeding this table now, not which sources did so a year ago.
Question 2: what depends on this table?
To find downstream consumers, reverse the filter. This is the first step of any impact assessment:
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 returns tables produced from main.sales.orders. It does not return dashboards or queries that only read it, because those rows have a null target. To see those readers, change the last filter and select the entity:
SELECT
entity_type,
entity_id,
created_by,
max(event_time) AS last_read
FROM system.access.table_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND target_table_full_name IS NULL
AND event_date >= current_date() - INTERVAL 30 DAYS
GROUP BY entity_type, entity_id, created_by
ORDER BY last_read DESC;Be aware of one edge case. Some reads that feed a write also appear as rows with a target. You should treat the null-target query as "pure readers" and the not-null-target query as "producers of other tables", and run both when you need a full picture.
Question 3: going more than one hop
The table stores one hop per row. To walk further, join the table to itself. This query finds tables two steps upstream of the target:
SELECT DISTINCT
l1.source_table_full_name AS two_hops_upstream,
l1.target_table_full_name AS one_hop_upstream,
l2.target_table_full_name AS target
FROM system.access.table_lineage AS l2
JOIN system.access.table_lineage AS l1
ON l1.target_table_full_name = l2.source_table_full_name
WHERE l2.target_table_full_name = 'main.sales.daily_revenue'
AND l1.source_table_full_name IS NOT NULL
AND l2.event_date >= current_date() - INTERVAL 90 DAYS
AND l1.event_date >= current_date() - INTERVAL 90 DAYS;Each additional hop adds another self-join. If you need an unknown depth, run the query repeatedly from a notebook, feeding each result into the next pass, or use a recursive common table expression if your SQL warehouse supports one. For routine exploration, Catalog Explorer draws this graph for you. SQL is better when you need a list you can filter, join to ownership data, or schedule.
Edge cases
- Time windows can hide a dependency. A table loaded only at month end will not show up in a 7-day query. Choose a window longer than your slowest schedule.
- Names can change. If a table was renamed, older rows keep the old name. Query both names when you investigate history.
- Views count as sources. A view appears with
source_typeofVIEW. A query on a view may also show its underlying tables, so you may see both in the results. - Paths are not tables. When the input is a storage path, the row has
source_pathset andsource_table_full_namenull. Filtering on table names alone will skip these rows. - Retention is finite. The table keeps a rolling window, which is documented as one year. Anything older is gone, so export results if you must keep them for an audit.
Putting it together
A typical investigation flows like this:
- Run the downstream query for the table you plan to change.
- Separate the results into producers (non-null target) and pure readers (null target).
- Group the readers by
entity_typeandcreated_byto find who to notify. - Check the time window. If the newest event is months old, the dependency may be dead.
Exercise
You run a query on system.access.tablelineage that filters on `sourcetablefullname = 'main.sales.orders' and targettablefull_name IS NOT NULL`. A dashboard that reads the table is missing from the results. Why, and how do you find it?
Show answer
Dashboards and ad hoc queries that only read the table produce rows with a null target_table_full_name, so the IS NOT NULL filter excludes them. Change the filter to target_table_full_name IS NULL, and group by entity_type, entity_id, and created_by to see which entities read the table.
Exercise
Why is it better to add event_date >= current_date() - INTERVAL 30 DAYS to a lineage query, and what risk comes with choosing too short a window?
Show answer
The filter reduces the amount of data scanned and keeps the results focused on current dependencies. If the window is shorter than the schedule of a periodic job, such as a monthly load, that job's rows are excluded and its dependency will look absent.