Regional Row Filtering, PII Masking, and Thirty Shadow Copies
One Unity Catalog metastore serves a company whose customers are in the EU and the US. A 400-person analytics community queries sales.customers, which holds name, email, national_id, region, and 40 other columns. Legal requires each analyst to see only rows for their own region, and only members of the pii_readers group may see national_id in clear; a fraud team needs the last four digits. Today the table is granted to account users at the schema level, and there are 30 copies of subsets of it spread across two catalogs, some of them full copies with no masking at all. Auditors want evidence of who read PII last quarter, and the copies must go away without breaking consumers.
1. Which Unity Catalog mechanisms implement the row and column restrictions, and why prefer them over views alone?
Read the worked answer
Use native row filters and column masks on the table, not per-consumer views:
- Row filter. A SQL UDF that returns a boolean, attached with
ALTER TABLE sales.customers SET ROW FILTER <fn> ON (region). The function compares the row's region to the caller's entitlement, derived fromis_account_group_member('eu_analysts')-style checks or a small mapping table joined oncurrent_user(). - Column mask. A UDF attached with
SET MASKonnational_idthat returns the value forpii_readers, the last four digits whenis_account_group_member('fraud_team'), and a redacted constant otherwise.
The advantage over views is coverage: filters and masks apply to SELECT *, to ad-hoc queries, to notebooks, and to every consumer of the table, and they cannot be bypassed by copying data out through a differently shaped query. A view protects only the paths that go through that view, which is how 30 unprotected copies came to exist. Keeping one governed table also means one place to audit. Validate the UDFs' return types and test with a non-privileged user before rolling out, since a mask that errors blocks all reads.
2. How do you retire the 30 copies without breaking the teams that depend on them, and how do you satisfy the regional residency requirement?
Read the worked answer
Find the consumers before touching anything. system.access.table_lineage (and column lineage) shows which dashboards, jobs, and queries read each copy; cross-check with job definitions and query history so you catch human ad-hoc readers too. Then replace each copy with a view over the governed table, created with CREATE OR REPLACE VIEW in the same schema under the same name so consumer SQL does not change, and granted to the same groups. A view created by a privileged owner lets callers read columns they cannot read directly, which is fine only when the view filters or projects explicitly, so do not let convenience views silently re-expose national_id.
Sequence it in waves, oldest and least-used copies first, with a deprecation window and a named owner for each.
For residency, put EU and US data in separate catalogs and bind each workspace to only its regional catalog. Analysts in the EU workspace then cannot see the US catalog at all, which is a stronger guarantee than a row filter and reduces the blast radius of a misconfigured grant.
3. What provides the audit evidence for last quarter, and what are the practical limits?
Read the worked answer
Unity Catalog audit records are queryable through the system.access.audit system table: filter to the read actions against sales.customers and the PII-bearing tables, and record actor, timestamp, and the accessed object. Join to lineage tables to show where the data flowed afterwards.
Practical limits to plan around:
- Retention. System table retention may be shorter than the audit window the auditors want; ship audit logs (and the raw cloud audit logs) to a storage bucket with a lifecycle policy that meets the retention requirement.
- Access to the audit data itself. Audit logs reveal who looked at what, so they must not be readable by
account users. Grant them to a small compliance group, and note that auditors reading the audit tables is itself audited. - Completeness. Audit covers Unity Catalog and workspace activity, not data downloaded to a laptop and read offline. Combined with column masks and the removal of unprotected copies, the audit story is credible; without those, it is not.
Also enable the system tables once and confirm they were on before last quarter started, or the evidence may not exist.