Metric View Materialization Failure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
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. RunEXPLAIN EXTENDEDto 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
SELECTgrants. - 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
MASKclause. 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:
- Materialization for metric views: https://docs.databricks.com/aws/en/uc-semantics/metric-views/materialization
- Row filters and column masks: https://docs.databricks.com/aws/en/data-governance/unity-catalog/filters-and-masks/
- ABAC requirements and limitations: https://learn.microsoft.com/en-us/azure/databricks/data-governance/unity-catalog/abac/requirements
- Wrapper views over metric views: https://docs.databricks.com/gcp/en/business-semantics/metric-views/bi-tools
- CREATE MATERIALIZED VIEW: https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/sql-ref-syntax-ddl-create-mat...
If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.
Regards, Louis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@Louis_Frolio Thanks for the reply.
I agree with you that metric views should be built on de-identified table/view. But coming to our situation we already have a whole lot of views over the years till now and this metric view concept is new as you know. So, If we want to utilize this feature and create metric views on top of existing view isn't there any workaround instead of building a whole lot of de-identified table/view from scratch?