- Use Row-Level Security (RLS) with Unity Catalog: If your dashboard is built on tables governed by Unity Catalog, you can define row filters at the table level. This ensures that users only see rows they are authorized to view, regardless of the dashboard.
How it works:
- Create a row filter function in Unity Catalog.
- Attach it to the table using ALTER TABLE ... SET ROW FILTER.
- The filter checks the user identity (e.g., current_user() or is_account_group_member()).
CREATE FUNCTION location_filter() RETURNS BOOLEAN
RETURN location = CASE current_user()
WHEN 'user1@company.com' THEN 'India'
WHEN 'user2@company.com' THEN 'Canada'
WHEN 'user3@company.com' THEN 'USA'
END;
2. Dynamic Views: If Unity Catalog is not enabled, you can create secure views that apply filters based on the user context.
Example:
CREATE OR REPLACE VIEW sales_filtered AS
SELECT *
FROM sales_data
WHERE location = CASE current_user()
WHEN 'user1@company.com' THEN 'India'
WHEN 'user2@company.com' THEN 'Canada'
WHEN 'user3@company.com' THEN 'USA'