Sub topic 13
Combining lineage and audit data for impact analysis
This chapter assumes you can read the SQL from the earlier chapters. You should know how system.access.table_lineage and system.access.audit are structured, and you should have SELECT on both tables (granted through the data-governance group in the earlier grants example).
The question impact analysis answers
Before you rename a column, change a table's type, or drop a table, you need two answers:
- What depends on this object? Lineage answers this.
- Who uses those dependents? Audit data answers this.
Lineage alone gives you a list of tables and jobs. It doesn't tell you which of them people still use. Audit data alone gives you users and actions, but not how objects are connected. Together they give you a ranked list of what to check and whom to notify.
Step 1: find downstream dependents
Start with the tables that read from the source. This is the query from the lineage chapter.
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;The entity_type column shows whether a job, notebook, or pipeline writes each target. That tells you who owns the fix.
This query returns direct dependents only. To follow the chain, run it again with each result as the new source. Stop when no new tables appear.
Step 2: check who reads the dependents
For one downstream table, look at recent metadata requests in the audit table.
SELECT
event_time,
user_identity.email AS user_email,
action_name,
request_params.full_name_arg AS table_name,
response.status_code
FROM system.access.audit
WHERE service_name = 'unityCatalog'
AND action_name = 'getTable'
AND request_params.full_name_arg = 'main.sales.daily_revenue'
AND event_date >= current_date() - INTERVAL 7 DAYS
ORDER BY event_time DESC;You can also join the two tables so one query covers every dependent. The query below counts distinct users per downstream table over 30 days.
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
)
SELECT
d.table_name,
count(DISTINCT a.user_identity.email) AS distinct_users,
max(a.event_time) AS last_access
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 distinct_users DESC;The LEFT JOIN keeps dependents with no recent access. Those rows show 0 users and a null last_access. They are candidates for retirement, or they may be consumed only by scheduled jobs.
Reading the results
| Result | Likely meaning | Action |
|---|---|---|
| Many users, recent access | Active dependency | Notify users and plan a migration window |
| Few users, a job as `entity_type` | Pipeline dependency | Contact the job owner and test the pipeline |
| No recent access | Possibly unused | Confirm with the owner before assuming it is safe |
Common errors
- Filtering audit data without
event_date. The table is large, so an unbounded query is slow and costly. - Treating lineage as complete. Lineage is captured only for supported operations, so some dependents will be missing.
- Forgetting column lineage. If only one column changes, check
system.access.column_lineageto narrow the list of affected tables. - Joining on the wrong name. The audit
full_name_arguses thecatalog.schema.tableform, so make sure the lineage values match it.
Exercise
You plan to change the type of revenue in main.sales.daily_revenue. Which two system tables do you query to find affected tables and the people who use them, and why use column lineage first?
Show answer
Query system.access.column_lineage (or table_lineage) to find downstream objects that read the column, then system.access.audit to see who accessed those objects recently. Column lineage narrows the list to objects that actually use revenue, so you don't notify owners of tables that only read other columns.