Databricks DE ยท Topic 8.3

Data-Level Security

Control which rows and column values each user sees โ€” row filters, column masks, and dynamic views, all keyed off user/group identity. This deep dive walks each with the verified SQL.

row filtercolumn maskdynamic viewis_account_group_member

The one-liner

Row filters hide rows (UDF RETURNS BOOLEAN), column masks redact values (transform UDF), and dynamic views wrap a table to filter/mask โ€” all varying by current_user() / is_account_group_member(). Object GRANT can't do this.
๐Ÿ“„ Analogy: a redacted document โ€” everyone gets "the same file," but a row filter removes whole paragraphs you're not cleared for, and a column mask blacks out specific words (emails) based on your clearance.

Same table, different view per role โ€” click a role

query: SELECT id, region, email FROM customers

Auditor (admin)
Support (no PII)
Manager โ€” West

Three mechanisms โ€” click each

Row filter โ€” UDF RETURNS BOOLEAN attached to the table; rows returning FALSE are hidden.
CREATE FUNCTION region_filter(region STRING) RETURNS BOOLEAN
  RETURN is_account_group_member('admins')
      OR is_account_group_member('region_' || region);
ALTER TABLE prod.sales.customers SET ROW FILTER region_filter ON (region);
Column mask โ€” UDF that transforms a column value per user; USING COLUMNS can reference other columns.
CREATE FUNCTION mask_email(e STRING) RETURNS STRING
  RETURN CASE WHEN is_account_group_member('pii_readers') THEN e ELSE '***@***' END;
ALTER TABLE prod.sales.customers ALTER COLUMN email SET MASK mask_email;
Dynamic view โ€” a view that filters/masks; grant the view instead of the table. Best for curated/shared slices.
CREATE VIEW prod.sales.cust_safe AS
SELECT id, region,
  CASE WHEN is_account_group_member('pii_readers') THEN email ELSE '***' END AS email
FROM prod.sales.customers
WHERE is_account_group_member('admins') OR is_account_group_member('region_' || region);

How it composes with GRANT (8.2)

Grants decide whether you can touch the table; filters/masks decide what you see once you can. A user still needs USE CATALOG + USE SCHEMA + SELECT โ€” and then the row filter/mask shapes the result.

Row filter / mask vs dynamic view

Row filter / column maskDynamic view
Attaches tothe base table (ALTER TABLE)a separate view object
Users querythe table directlythe view (grant on view)
Best foruniversal table-level enforcementcurated/shared data slices

Why it matters

๐Ÿ” Real-world use case: one customers table โ€” support sees all rows but email masked; regional managers see only their region's rows; auditors see everything.

Uses, edge cases & limitations

Common gotchas