Sub topic 13
Combining lineage and audit data for impact analysis
Impact analysis answers one question before you change something: who and what will break? Lineage tells you which objects depend on the one you are changing. Audit logs tell you which people and jobs actually use those dependents. This chapter joins the two.
This chapter assumes you can read system.access.table_lineage, system.access.column_lineage, and system.access.audit directly. It also assumes you can run SQL on a warehouse and that your group already has the grants shown earlier in the tutorial.
Why you need both sources
Each source leaves a gap that the other fills.
| Source | What it tells you | What it cannot tell you |
|---|---|---|
| `table_lineage` | Which tables, jobs, and notebooks read or wrote a table | Which humans look at the downstream tables |
| `column_lineage` | Which source columns feed which target columns | Whether anyone still uses the result |
| `audit` | Who requested metadata for a securable, and when | What depends on that securable |
A downstream table that nobody has touched in six months is a different risk from one that a finance team opens daily. Lineage alone gives you the first list. Audit data ranks it.
Step 1: Find the downstream tables
Start from the object you plan to change. This query lists every table that read from main.sales.orders in the last 90 days.
SELECT DISTINCT
target_table_full_name,
entity_type,
created_by
FROM system.access.table_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND target_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS
ORDER BY target_table_full_name;Three details matter here.
- Always filter on
event_date. It limits the scan and keeps the window explicit, so you know how far back "no dependents" really reaches. entity_typeshows what did the work, for example a job, notebook, or pipeline. This tells you who to contact.created_byis the identity that ran the operation. For a scheduled job, that is usually a service principal, not a person.
Step 2: Narrow by column
If you are renaming or dropping one column, most downstream tables are unaffected. Column lineage removes the false positives.
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 = 'order_total'
AND target_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS;Compare this list with the table-level list. Tables that appear in the first and not in the second read orders but never use order_total. They are safe for this change.
Step 3: Follow the chain a second hop
Impact does not stop at the first level. A dashboard table built from daily_revenue is affected by a change to orders even though it never reads orders. A self-join extends the search by one hop.
WITH hop1 AS (
SELECT DISTINCT target_table_full_name AS table_name
FROM system.access.table_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND target_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS
),
hop2 AS (
SELECT DISTINCT l.target_table_full_name AS table_name
FROM system.access.table_lineage l
JOIN hop1 h ON l.source_table_full_name = h.table_name
WHERE l.target_table_full_name IS NOT NULL
AND l.event_date >= current_date() - INTERVAL 90 DAYS
)
SELECT table_name, 1 AS hops FROM hop1
UNION
SELECT table_name, 2 AS hops FROM hop2
WHERE table_name NOT IN (SELECT table_name FROM hop1)
ORDER BY hops, table_name;Each added hop means another CTE. For deep pipelines, switch to the lineage graph in Catalog Explorer, which expands levels interactively. Use SQL when you need a list you can store, join, or schedule.
Step 4: Join the dependents to audit events
Now rank the affected tables by who has recently looked at them. The audit table identifies a table in request_params.full_name_arg, which uses the same catalog.schema.table form as the lineage columns. That shared name is the join key.
WITH downstream AS (
SELECT DISTINCT target_table_full_name AS table_name
FROM system.access.table_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND target_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS
)
SELECT
d.table_name,
count(DISTINCT a.user_identity.email) AS distinct_users,
count(*) AS events,
max(a.event_time) AS last_seen
FROM downstream d
JOIN system.access.audit a
ON a.request_params.full_name_arg = d.table_name
WHERE a.service_name = 'unityCatalog'
AND a.action_name = 'getTable'
AND a.event_date >= current_date() - INTERVAL 30 DAYS
GROUP BY d.table_name
ORDER BY distinct_users DESC, last_seen DESC;Read the output as a priority list. A table with many distinct users and a recent last_seen needs a communication plan. A table with no rows in this result was not requested in the last 30 days, which makes it a candidate for deprecation rather than protection.
To see the people behind one table, group by user instead.
SELECT
a.user_identity.email AS user_email,
count(*) AS events,
max(a.event_time) AS last_seen
FROM system.access.audit a
WHERE a.service_name = 'unityCatalog'
AND a.action_name = 'getTable'
AND a.request_params.full_name_arg = 'main.sales.daily_revenue'
AND a.event_date >= current_date() - INTERVAL 30 DAYS
GROUP BY a.user_identity.email
ORDER BY events DESC;An INNER JOIN drops downstream tables with no audit events. If you want to list those quiet tables explicitly, change the join to a LEFT JOIN and move the audit filters into the ON clause, as the next example shows.
WITH downstream AS (
SELECT DISTINCT target_table_full_name AS table_name
FROM system.access.table_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND target_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS
)
SELECT
d.table_name,
count(a.event_time) AS events
FROM downstream d
LEFT JOIN system.access.audit a
ON a.request_params.full_name_arg = d.table_name
AND a.service_name = 'unityCatalog'
AND a.action_name = 'getTable'
AND a.event_date >= current_date() - INTERVAL 30 DAYS
GROUP BY d.table_name
ORDER BY events ASC;If the filters stayed in a WHERE clause, they would turn the left join back into an inner join. This is the most common mistake in this kind of query.
Reading the results with care
The two sources measure different things, so treat the joined result as evidence and not as proof.
getTableis a metadata request. It shows that someone or something asked Unity Catalog about the table. It does not count rows read or queries run. Use it to find interest, not to measure volume.- Lineage is limited by what ran. A table read by a job that has not run in your lookback window will not appear. Match the lookback to your slowest schedule. A quarterly job needs a window longer than 90 days.
- Retention is finite. System table data is kept for a limited period, so a long window may silently return less than you expect. Check the retention rules for your account before you rely on a negative result.
- Service principals are users too. Automated consumers show up under application IDs. A table with no human users may still feed a production job, so check
created_byandentity_typefrom the lineage side.
Saving the analysis for reuse
If you run impact analysis often, store the result as a view so that teams can check it without writing the join. Keep the view in a catalog you control, and grant access to the view only. Remember that the view exposes user emails from the audit table, so share it with the same care as the audit table itself.
CREATE OR REPLACE VIEW main.governance.orders_impact AS
SELECT
l.target_table_full_name AS table_name,
count(DISTINCT a.user_identity.email) AS distinct_users,
max(a.event_time) AS last_seen
FROM (
SELECT DISTINCT target_table_full_name
FROM system.access.table_lineage
WHERE source_table_full_name = 'main.sales.orders'
AND target_table_full_name IS NOT NULL
AND event_date >= current_date() - INTERVAL 90 DAYS
) l
LEFT JOIN system.access.audit a
ON a.request_params.full_name_arg = l.target_table_full_name
AND a.service_name = 'unityCatalog'
AND a.action_name = 'getTable'
AND a.event_date >= current_date() - INTERVAL 30 DAYS
GROUP BY l.target_table_full_name;Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Join returns no rows | Name mismatch, such as different case or missing catalog | Compare `full_name_arg` and the lineage name for one known table |
| Quiet tables vanish from the result | Inner join or `WHERE` filter on the audit side | Use `LEFT JOIN` with filters in `ON` |
| Query is slow | No `event_date` filter | Add date bounds on both system tables |
| Permission denied | Missing `USE SCHEMA` or `SELECT` on a system table | Re-check the grants on `system.access` |
| Known dependent missing | Job has not run inside the lookback window | Widen the window or ask the job owner |
Exercise
You plan to drop the column discount_code from main.sales.orders. Describe, in order, the queries you would run to decide whether it is safe, and name the join mistake that would hide quiet downstream tables.
Show answer
First, query system.access.column_lineage with source_table_full_name = 'main.sales.orders' and source_column_name = 'discount_code', filtered on event_date, to list the target tables and columns that use it. Second, extend the result by one or more hops with table_lineage to catch tables built from those targets. Third, join the downstream names to system.access.audit on request_params.full_name_arg, filtered to service_name = 'unityCatalog' and action_name = 'getTable', to see which affected tables have recent users. Check created_by and entity_type to find the owning jobs. The join mistake is putting the audit filters in the WHERE clause of a left join, which turns it into an inner join and drops tables with no recent audit events.
Exercise
A query shows no audit events in the last 30 days for a downstream table. Give two reasons you should still not drop it at once.
Show answer
The table may be read by a job that runs less often than every 30 days, so the window missed it. Also, getTable records metadata requests only, and system table retention is limited, so the absence of events is not proof of non-use. Announce the change and wait before dropping it.