Hello @Avinash_Narala, I took a look at both internal and external documentation and here is what I found.
What you're seeing is by design. A materialization is computed once, under the owner's identity, and then served to everyone. If the source returns different values depending on who's asking, the stored result would either leak the clear value or show the wrong one. Your screenshot shows METRIC_VIEW_MATERIALIZATION_WITH_INVOKER_DEPENDENT_EXPRESSIONS_NOT_SUPPORTED, which fires when anything in the dependency chain uses functions like current_user() or is_account_group_member(). Row filters, column masks, and ABAC policies on the sources are blocked for the same reason. Masking the metric view itself isn't possible either: views don't accept column masks, and ABAC policies can't target metric views.
So there's no switch for this. The fix is moving the masking to a different layer:
- Sanitize upstream. Build a de-identified table in your pipeline (hash, tokenize, or drop the PII columns), attach no masks to it, and point the metric view there. This is the cleanest route if your fields and measures don't need the raw values.
- Materialize first, mask on the way out. Build the metric view on an unmasked source so it materializes, then expose it through a dynamic view and revoke direct access to the metric view. The wrapper has to use
MEASURE() and a fixed set of dimensions, so you need one per query shape. Run EXPLAIN EXTENDED to confirm queries through the wrapper still hit the materialization.
- Split by audience. Keep one materialized metric view without the sensitive field for general use and a second with the clear column for the privileged group, controlled by
SELECT grants.
- Stay unmaterialized and fix the timeout upstream. Pre-compute the expensive joins in a standalone materialized view, cluster it on your common filter columns, and put the column mask there with the
MASK clause. The mask is still enforced per user at query time. One caveat: a materialized view over sources that carry row filters or column masks always does a full refresh.
A wrapper for the second option looks like this:
CREATE OR REPLACE VIEW catalog.schema.sales_secure AS
WITH agg AS (
SELECT region, customer_email, MEASURE(total_revenue) AS total_revenue
FROM catalog.schema.sales_metric_view
GROUP BY ALL
)
SELECT
region,
CASE WHEN is_account_group_member('pii_readers') THEN customer_email ELSE '***' END AS customer_email,
total_revenue
FROM agg;
For the timeouts in the meantime, check the query profile to see where the time goes, and consider a larger SQL warehouse.
References:
If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.
Regards, Louis.