Data Engineer Associate · Domain 7: Governance and Security · 15% of the exam
Task 7.3: Understand column-level masking and row-level security to restrict data visibility based on user groups.
SQL user-defined functions as row filters and column masks, is_account_group_member, applying them with ALTER TABLE, and dynamic views.
Study it
Row filters, column masks and dynamic views
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the Databricks documentation page that proves it.
Question 1 · choose 1
A table owner creates one function for several regional tables:
CREATE FUNCTION main.sec.region_rf(region STRING, allowed STRING) RETURN region = allowed;
The table main.sales.orders_eu must return only rows whose region is 'EU', and main.sales.orders_us only rows whose region is 'US', both from this one function. Which statement applies it to main.sales.orders_eu?
AALTER TABLE main.sales.orders_eu SET ROW FILTER main.sec.region_rf ON (region)
BALTER TABLE main.sales.orders_eu SET ROW FILTER main.sec.region_rf ON (region, 'EU')
CALTER TABLE main.sales.orders_eu SET ROW FILTER main.sec.region_rf('EU') ON (region)
A CHECK constraint tests rows that are written, not rows that are read, and its expression cannot use user-defined functions.
A row filter is a SQL UDF that returns BOOLEAN, applied with ALTER TABLE ... SET ROW FILTER ... ON (...). Each entry in the ON list is a column name or a constant literal of a supported type, so one function can serve several tables with a different constant on each: ON (region, 'EU') here and ON (region, 'US') on the other table.
The ssn column of main.hr.people must show the full value to members of the account group hr and '***-**-****' to everyone else. The table owner has created main.sec.mask_ssn(ssn STRING), which returns ssn for hr members and the mask otherwise. Which statement applies it?
AALTER TABLE main.hr.people SET ROW FILTER main.sec.mask_ssn ON (ssn)
BALTER TABLE main.hr.people ADD CONSTRAINT ssn_masked CHECK (main.sec.mask_ssn(ssn) IS NOT NULL)
CALTER TABLE main.hr.people DROP COLUMN ssn
DALTER TABLE main.hr.people ALTER COLUMN ssn SET MASK main.sec.mask_ssn
Show the answer and why
AALTER TABLE main.hr.people SET ROW FILTER main.sec.mask_ssn ON (ssn)
Incorrect
A row filter removes rows; it needs a boolean function and does not change column values.
BALTER TABLE main.hr.people ADD CONSTRAINT ssn_masked CHECK (main.sec.mask_ssn(ssn) IS NOT NULL)
Incorrect
CHECK constraints validate writes, cannot call user-defined functions and do not change what readers see.
CALTER TABLE main.hr.people DROP COLUMN ssn
Incorrect
Dropping the column removes the data for hr members as well.
DALTER TABLE main.hr.people ALTER COLUMN ssn SET MASK main.sec.mask_ssn
Correct
SET MASK binds the function to the column, so each query returns the function's result for the reader.
A column mask is a SQL function that returns the original or a masked value of the column's type, applied with ALTER COLUMN ... SET MASK.
A row filter function on a Unity Catalog table must check whether the querying user belongs to the finance group, which is managed at the account level. Which function should it call?
Ais_member('finance')
Bis_account_group_member('finance')
Ccurrent_user() = 'finance'
Dsession_user() = 'finance'
Show the answer and why
Ais_member('finance')
Incorrect
is_member tests groups as the workspace sees them; Databricks advises is_account_group_member for testing account-level membership.
Bis_account_group_member('finance')
Correct
This returns true when the session user is a direct or indirect member of the account-level group.
Ccurrent_user() = 'finance'
Incorrect
current_user returns the user's name, which never equals a group name.
Dsession_user() = 'finance'
Incorrect
session_user also returns the connected user, not their groups.
For Unity Catalog row filters, column masks and dynamic views, test group membership with is_account_group_member.
A partner group must see a joined, curated version of two tables, with email addresses redacted unless the user is in auditors. The group must not be able to read the two base tables. Which approach fits?
ARow filters and column masks on both base tables, with SELECT on the tables granted to the group
BAn ABAC column mask policy on the catalog, with SELECT on the base tables granted to the group
CA dynamic view over the join using is_account_group_member, granted to the group
DA nightly job that copies the joined data, with emails masked, into a new table
Show the answer and why
ARow filters and column masks on both base tables, with SELECT on the tables granted to the group
Incorrect
The group would then have access to the base tables, which the requirement rules out.
BAn ABAC column mask policy on the catalog, with SELECT on the base tables granted to the group
Incorrect
ABAC also protects base tables that the group would still be able to query.
CA dynamic view over the join using is_account_group_member, granted to the group
Correct
Dynamic views expose a curated or joined version of data with masking logic, to users who lack access to the underlying tables.
DA nightly job that copies the joined data, with emails masked, into a new table
Incorrect
A copy goes stale between runs and duplicates the data.
Dynamic views suit fine-grained access over several tables or reshaped data; row filters and column masks protect individual tables in place.
A table owner ran DROP FUNCTION on a function that was still set as a table's row filter. Now every query on the table fails. How should the owner fix the table?
ARun ALTER TABLE ... DROP ROW FILTER on the table
BRun UNDROP FUNCTION on the function
CRecreate the table with CREATE OR REPLACE TABLE
DRevoke EXECUTE on the function from the account users group
Show the answer and why
ARun ALTER TABLE ... DROP ROW FILTER on the table
Correct
Dropping the orphaned row filter reference makes the table accessible again; the filter should be dropped before the function.
BRun UNDROP FUNCTION on the function
Incorrect
UNDROP has no form for functions, so the dropped function cannot be brought back this way.
CRecreate the table with CREATE OR REPLACE TABLE
Incorrect
Replacing a table keeps its existing row filter, so the broken reference would remain.
DRevoke EXECUTE on the function from the account users group
Incorrect
The function no longer exists, and privileges do not repair the table's reference to it.
Remove a row filter with ALTER TABLE ... DROP ROW FILTER before dropping its function; doing it in the other order leaves the table inaccessible.