Databricks DE ยท Topic 8.3
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.
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.query: SELECT id, region, email FROM customers
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);
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;
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);
USE CATALOG + USE SCHEMA + SELECT โ and then the row filter/mask shapes the result.| Row filter / column mask | Dynamic view | |
|---|---|---|
| Attaches to | the base table (ALTER TABLE) | a separate view object |
| Users query | the table directly | the view (grant on view) |
| Best for | universal table-level enforcement | curated/shared data slices |
customers table โ support sees all rows but email masked; regional managers see only their region's rows; auditors see everything.is_account_group_member() or a mapping table (no invented helper functions).RETURNS BOOLEAN (row filter) / RETURNS <type> (mask) in the signature.is_account_group_member() / current_user() or a mapping table.