CertSafari
    Databricks Certified Data Engineer Professional - October 9 onwards· Lessons

    Domain 9 · Lesson 46/46

    Unity Catalog Metric Views: Governed Metrics and Materialization

    Design dimensional models for analytical workloads, leveraging Materialized Views for pre-computed aggregation and Unity Catalog Metric Views for governed, reusable metric definitions, to ensure efficient querying and aggregation.

    11 min read
    2.5% of exam
    5 sources
    Published 2 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Explain how a metric view differs from a standard view and why it gives consistent KPIs
    • Define sources, joins, filters, fields and measures in metric view YAML and query measures with MEASURE()
    • Choose between aggregated and unaggregated materializations for a metric view
    • Predict when relaxed-mode query rewrite serves stale data and when materialization is blocked

    1.Why metric views: define once, group by anything

    A standard view fixes its aggregations and groupings when you create it. To see revenue by month and by region, you need two views, and each repeats the revenue formula. A Unity Catalog metric view keeps the measure definitions separate from the fields (dimensions) used to group and filter them. You define a metric such as revenue per distinct customer once. Users can then group it by any available field, and the query engine generates the correct computation at runtime.

    This is the governance benefit. Every KPI has one registered definition in Unity Catalog, so everyone in the organisation reports the same value for the same metric.

    The components of a metric view
    ComponentWhat it definesExample
    SourceThe base table, view, or SQL query containing the datasamples.tpch.orders
    JoinsRelationships to other tables, views, and metric viewsJoin orders with customers on customer_key
    FiltersConditions that scope the source datastatus = 'completed'
    Fields (dimensions)Columns used to group, filter, and aggregate metricsProduct category, Order month
    MeasuresColumn aggregations that produce metricsSUM(o_totalprice) as Total Revenue

    A source can be any table-like Unity Catalog asset, including tables, views, materialized views, streaming tables and other metric views, or it can be a SQL query. A gold star schema therefore plugs in directly. Use the fact table as the source and the dimensions as joins. If the source is a SQL query containing a JOIN, declare primary and foreign key constraints with the RELY option for the best performance.

    Checkpoint 1 of 6· Check yourself

    Finance and sales each built standard views that compute 'average order value' slightly differently, and their dashboards disagree. What does a metric view change?

    Sources12

    2.Fields, measures and the MEASURE() function

    Fields behave like ordinary columns: you can use them in SELECT, WHERE and GROUP BY. A field can be a categorical column such as region, or an unaggregated numeric column such as price. Measures must be aggregate expressions, and they have no fixed level of aggregation; the grouping in each query decides it. A measure can combine aggregations, as in a ratio, or apply a FILTER (WHERE ...) clause.

    Measure patterns in metric view YAMLyaml
    measures:
      # Simple count measure
      - name: Order Count
        expr: COUNT(1)
    
      # Sum aggregation measure
      - name: Total Revenue
        expr: SUM(o_totalprice)
    
      # Distinct count measure
      - name: Unique Customers
        expr: COUNT(DISTINCT o_custkey)
    
      # Calculated measure combining multiple aggregations
      - name: Average Order Value
        expr: SUM(o_totalprice) / COUNT(DISTINCT o_orderkey)

    You can define a metric view in Catalog Explorer, with built-in YAML validation, or in SQL by wrapping the YAML in a CREATE VIEW statement that has a WITH METRICS clause and placing the YAML between $$ delimiters.

    Checkpoint 2 of 6· Fill the gap

    Which keyword turns this CREATE VIEW statement into a metric view definition?

    CREATE OR REPLACE VIEW catalog.schema.orders_materialized WITH  ?  LANGUAGE YAML AS

    No. Every measure in a query must be wrapped in the MEASURE() aggregate function, so you list fields and measures explicitly instead of using SELECT *. You also can't join a metric view directly to other tables at query time. To combine it with another table, wrap the metric view query in a CTE and join the CTE result.

    Querying a metric view: fields are listed directly and measures are wrapped in MEASURE()sql
    SELECT
      `Order Month`,
      `Order Status`,
      MEASURE(`Order Count`),
      MEASURE(`Total Revenue`)
    FROM orders_metric_view
    GROUP BY ALL
    ORDER BY `Order Month`;

    Checkpoint 3 of 6· Exam question

    A team builds a standalone `daily_revenue_by_region` materialized view on top of an hourly-updating `fact_sales` table. Stakeholders want the view to reflect new source data within a few minutes of it landing, but they do not want a pipeline running on a fixed timer when no new data has arrived, since that would waste serverless compute. Which materialized view refresh configuration best meets this requirement?

    Sources234

    3.Materializing a metric view: aggregated vs unaggregated

    Metric views compute at runtime, but you can still pre-compute them. Add a top-level materialization block to the YAML, and Databricks creates a managed Lakeflow pipeline that builds and maintains the materialized views on the schedule you set. You keep querying the metric view itself. The optimizer uses aggregate-aware query rewriting: it takes the fast path and reads a suitable materialization when one exists, and otherwise falls back to the source data. The metric view remains the single source of truth for what the metric means. Materialization only changes how it is stored. It requires serverless compute for the pipelines and Databricks Runtime 17.3 or above.

    A materialization block with one unaggregated and one aggregated materialized view; cluster_by controls physical layoutyaml
    materialization:
      schedule: every 6 hours
      mode: relaxed
    
      materialized_views:
        - name: baseline
          type: unaggregated
    
        - name: revenue_breakdown
          type: aggregated
          dimensions:
            - category
            - color
          measures:
            - total_revenue
          cluster_by:
            cols:
              - category
              - color
    Choosing a materialization type for a metric view
    Aspectaggregatedunaggregated
    What it storesPre-computed results for specific dimensions and measuresThe full data model: source, joins, filter, and fields
    Which queries it servesExact match on its dimensions, or rollup to a subset of themAny query shape
    Use it whenSpecific dimension and measure combinations are queried frequentlySource transformations or joins are expensive, query patterns are unpredictable, or all users must see consistent data
    Trade-offBest performance, but only for the shapes it coversWider coverage with less performance lift; no benefit over a direct table reference without a selective filter

    To get good aggregated coverage, materialize at the finest grain your queries need, and include the columns that users filter on. A materialization at (region, sku, event_day) can serve GROUP BY region, GROUP BY region, event_month, and GROUP BY sku with WHERE region = 'US'. Don't go so fine that most groups contain a single row, such as millisecond timestamps, which only adds storage. Non-additive measures like COUNT(DISTINCT), MEDIAN and percentiles can't be rebuilt from partial results, so they need an exact match. If both types exist, Databricks computes the aggregated materializations from the unaggregated one, which gives a consistent snapshot.

    Checkpoint 4 of 6· Check yourself

    An aggregated materialization stores number_of_suppliers, defined as COUNT(DISTINCT supplier_id), by (category, color). A user queries number_of_suppliers grouped only by category. What happens?

    Sources5

    4.Relaxed mode, freshness, and what blocks materialization

    The materialization mode is always relaxed. In relaxed mode, query rewrite checks only whether a candidate materialization contains the fields and measures the query needs. It does not check freshness, SQL settings such as TIMEZONE or ANSI_MODE, or determinism. So two queries against the same metric view can see different data: a query that matches a materialization reads its last refresh, while a query that doesn't match reads live source data. To limit the gap, schedule materialization refreshes to run after your source pipeline completes, or use an unaggregated materialization so that every query reads the same snapshot.

    The same reasoning rules out invoker-dependent expressions, whose results depend on who runs the query, such as current_user() or is_member(). Databricks validates this when you create, alter or refresh a materialization. These operations fail with METRIC_VIEW_MATERIALIZATION_WITH_INVOKER_DEPENDENT_EXPRESSIONS_NOT_SUPPORTED.

    Checkpoint 5 of 6· Match them up

    Match each situation to how a materialized metric view behaves

    Tap a term, then the definition that fits it.

    Checkpoint 6 of 6· Exam question

    A materialized view aggregating `fact_orders` by region is expected to refresh incrementally, but `EXPLAIN CREATE MATERIALIZED VIEW` shows every refresh performing a full recompute of the entire view instead of merging only the changed rows. The source `fact_orders` table is a Delta table that has never had any table properties explicitly set. What is the most likely cause, and how should the team fix it?

    Sources5

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.One aggregated materialization at a coarse grain can serve any grouping of its measures through rollup.Why is that wrong?

      An aggregation serves only queries on exactly its dimensions or on a subset of them, and non-additive measures need an exact match. Databricks recommends several aggregated materializations for different query shapes.

      Covered in Materializing a metric view: aggregated vs unaggregated

    2. 2.Query rewrite to a materialization guarantees the result is as fresh as the source data.Why is that wrong?

      Relaxed mode checks only that the fields and measures are present. It skips the freshness check, so matched queries return the last refresh while unmatched queries return live data.

      Covered in Relaxed mode, freshness, and what blocks materialization

    3. 3.You can materialize a metric view over tables protected by row filters or column masks, and the security policies will still apply per user.Why is that wrong?

      A materialization is computed once under the owner's identity, so it would bypass per-user controls. Materialization is therefore blocked when RLS, column masks or ABAC policies are present.

      Covered in Relaxed mode, freshness, and what blocks materialization

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Standard views lock in aggregations and groupings at creation time.”
      ↩︎ Why metric views: define once, group by anything
      “users can group by any available field. The query engine generates the correct computation.”
      ↩︎ Why metric views: define once, group by anything
    2. 2.
      “A table-like asset is any Unity Catalog object that exposes a tabular schema and supports SELECT queries”
      ↩︎ Why metric views: define once, group by anything
      “set primary and foreign key constraints on underlying tables and use the RELY option for optimal query performance.”
      ↩︎ Why metric views: define once, group by anything
      “Measures are expressions that produce results without a pre-determined level of aggregation.”
      ↩︎ Fields, measures and the MEASURE() function
      “Fields, also called dimensions, are metric view columns that you can use in SELECT, WHERE, and GROUP BY clauses at query time.”
      ↩︎ Fields, measures and the MEASURE() function
      “As a result, every user across the organization reports the same value for the same KPI, which eliminates inconsistent reporting”
      ↩︎ Checkpoint
    3. 3.
      “wrap the YAML definition in a CREATE VIEW statement with the WITH METRICS clause, and place the YAML between $$ delimiters”
      ↩︎ Fields, measures and the MEASURE() function
    4. 4.
      “Because measures require the MEASURE() function to evaluate properly, you must specify individual columns rather than using SELECT *.”
      ↩︎ Fields, measures and the MEASURE() function
      “Metric views cannot be directly joined with other tables at query time.”
      ↩︎ Fields, measures and the MEASURE() function
    5. 5.
      “At query time, the query optimizer routes queries to the best materialized view using automatic aggregate-aware query matching (query rewriting).”
      ↩︎ Materializing a metric view: aggregated vs unaggregated
      “From that definition, Databricks creates a managed Lakeflow pipeline that builds and maintains the materialized views.”
      ↩︎ Materializing a metric view: aggregated vs unaggregated
      “Each materialized view is either aggregated, which pre-computes specific dimensions and measures, or unaggregated, which materializes the full data model.”
      ↩︎ Materializing a metric view: aggregated vs unaggregated
      “When both aggregated and unaggregated materializations exist, Databricks computes the aggregated materializations from the unaggregated one.”
      ↩︎ Materializing a metric view: aggregated vs unaggregated
      “Alternatively, use an unaggregated materialization to guarantee that all queries read from the same snapshot.”
      ↩︎ Relaxed mode, freshness, and what blocks materialization
      “Invoker-dependent expressions, whose result changes based on who runs the query (for example, current_user() or is_member()).”
      ↩︎ Relaxed mode, freshness, and what blocks materialization
      “A single aggregation can only serve queries that match its specific dimensions (exact match) or a subset of its dimensions (rollup match).”
      ↩︎ Exam trap 1
      “In relaxed mode, automatic query rewrite only verifies whether candidate materialized views have the necessary fields and measures to serve the query.”
      ↩︎ Exam trap 2
      “Because a materialization is pre-computed once using the owner's identity, serving it to other users would bypass the per-user access controls”
      ↩︎ Exam trap 3
      “Non-additive measures can't be re-aggregated from partial results (for example, COUNT(DISTINCT), MEDIAN, and percentiles) and require an exact match against a materialization.”
      ↩︎ Checkpoint
      “Queries that match a materialization use the last refresh. Queries that don't match fall back to source and return live data.”
      ↩︎ Checkpoint

    Spotted a mistake, or was something unclear? Tell us.