Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 08:37 AM - edited 02-11-2025 08:54 AM
Hello @TejeshS ,
We cannot directly mask a view since we cannot alter it or add data to it. However, we can apply column masking at the view level using Databricks Dynamic Views. This allows us to control access to specific columns based on the user's role.
For example, we can create a view where the Salary column is only visible to ab***@gmail.com and xy****@gmail.com while all other users see a masked value like "Masked".This is achieved using a Case When condition that checks the current user.
Sample Query :
CREATE OR REPLACE VIEW masked_employees AS
SELECT
Name,
Department,
CASE
WHEN current_user() IN ('ab***@gmail.com', 'xy***@gmail.com') THEN Salary
ELSE 'MASKED'
END AS Salary
FROM employees;
SELECT
Name,
Department,
CASE
WHEN current_user() IN ('ab***@gmail.com', 'xy***@gmail.com') THEN Salary
ELSE 'MASKED'
END AS Salary
FROM employees;
Akshay Petkar