cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Metric View Materialization Failure

Avinash_Narala
Databricks Partner

While trying to develop metric view in databricks, I encountered with below error.

I am using a pii view toget a column to build my final metric view, this is blocking on having the materialization to metric view because of masking functions used while building the pii view, without materialization any query on metric view is being timed out.

I know there is a limitation "Materialization Doesnโ€™t Support Column Masking and Row-Level Security" but are there any workarounds on this? Because as metric views will be build using multiple semantic views and avoiding pii views will be inevitable when working in enterprise level.

Avinash_Narala_0-1795538949326.png

1 REPLY 1

Louis_Frolio
Databricks Employee
Databricks Employee

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.