Skip to main content
  • AI agents increasingly need to answer questions across independently governed business metrics, without data modelers having to anticipate every combination of metrics, dimensions, and filters in advance.
  • We're introducing two new capabilities in Unity Catalog Semantics: query-time joins, which allow metric views to be composed directly in SQL while preserving measure correctness, and relationship constraints, which allow agents and BI tools to discover how metric views can be joined.
  • Together, these capabilities enable agents to answer new business questions using centrally governed metric definitions, without requiring monolithic or overlapping semantic models. Both features are now in Beta.

Traditional semantic models bring together the tables, relationships, and metrics needed to answer a set of business questions. This approach has worked well for BI, where the scope of analysis is often known when a model is built. But with AI agents, the scope of analysis is increasingly determined at query time. Users can ask questions spanning sales, support tickets, and product usage, even when the corresponding metrics are defined and governed independently by different teams. Anticipating every combination of metrics and dimensions at modeling time would require either unwieldy semantic models or a proliferation of redundant ones.

At Databricks, we’re taking a different approach to semantic modeling. In April, we released Unity Catalog metric views, a SQL-first way to define and govern business metrics. Since then, many customers have adopted metric views as the foundation of their semantic layer.

Today, we're excited to announce two new features in Unity Catalog Semantics that enable agents to compose independently governed metrics directly in SQL at query time:

  • Query-time joins. Metric views can now be joined with other metric views, tables, and views in ordinary SQL. The SQL engine protects measures from join-induced duplication, even across many-to-many joins, allowing metrics and dimensions from multiple data sources to be combined on the fly. To learn more about query-time joins please read the product documentation.
  • Relationship constraints. Using familiar SQL informational constraints, data modelers can now define relationships between metric views directly in Unity Catalog. Agents and BI tools can discover these relationships and use them to generate joins across independently governed metric views. To learn more about relationship constraints joins please read the product documentation.

Together, these features separate the governance of business metrics and relationships from the scope of individual analyses. Data modelers govern these definitions in Unity Catalog, while AI agents, including those powered by Genie, can combine them at query time to answer new business questions.

The challenge of composing measures in SQL

A common problem in business analytics is combining metrics from different data sources. Suppose your company stores sales transactions and support tickets in two separate tables, but you want to consolidate them and view both broken down by region. A natural way to write this query in SQL would be to join the two tables on region, then compute the total sales amount and count all the support tickets:

Unfortunately, this simple query can produce wrong results. If a region has multiple sales and multiple tickets, then the join duplicates sales and tickets, producing incorrect aggregates. This unexpected behavior is commonly referred to as a chasm trap and often trips up an unsuspecting user.

Traditional semantic models address this problem by controlling how queries are constructed and how measures are evaluated. This typically requires users and tools to query through model-specific interfaces or drag-and-drop UI.

Unity Catalog Semantics takes a different approach: the protection against join-induced duplication is built into the SQL engine itself. Users, agents, and BI tools can construct rich SQL queries while relying on Databricks to preserve the correct aggregation semantics of governed measures.

Metric views as composable building blocks

Metric views are like SQL views or tables, but they can include business metrics.

They have two kinds of columns:

  • Fields are normal columns: you can filter on them, group by them, and join on them. They are typically used for dimensions or facts.
  • Measures define business metrics. They carry an aggregate calculation together with the identity of the source rows it aggregates, so that the engine knows how to avoid duplicating rows.

A measure can be as rich as the business requires, from SUM(amount) to ratios of other measures, running totals, and semi-additive balances. Measures are evaluated in SQL with MEASURE(), an aggregate function that goes anywhere an aggregate function goes: the SELECT list, HAVING, ORDER BY, subqueries, and CTEs:

Unlike traditional semantic models whose semantics change dynamically based on the requested measures and dimensions, a metric view preserves the relational behavior of a SQL view. This means:

  • Its fields can be used in ordinary SQL, and adding a measure to a query does not change the underlying set of rows.
  • MEASURE() responds to WHERE and GROUP BY just as a standard aggregate over the measure's definition would, so filtering and slicing behave predictably.
  • Metric views are composable: one can serve as a building block for another.

Composing governed metrics with query-time joins

Previously you could query metric views in SQL, but a metric view had to be by itself in the FROM clause. Now you can join metric views with normal tables or views, or even with other metric views. The engine guarantees that joins do not inflate measures. Each source row contributes at most once per group, regardless of how many joined rows it produces; this is how we prevent chasm and fan traps.

This unlocks powerful analytic scenarios: flexible, on-the-fly analysis for users and agents, and reusable complex metric view source definitions for modelers.

Enrich metric views at query time

Suppose a colleague has created a metric view, sales_metric_view, with a total_sales measure and a region dimension. But you want to roll up sales to the country level. Rather than having to ask your colleague to add country to their metric view, you can join a geography table at query time:

The same pattern applies to joining fiscal calendars, customer attributes, and other business dimensions defined outside the metric view. You (or your agent) can extend an analysis using ordinary SQL without changing the governed metric view.

Combine independently governed metrics

You can also join two metric views to analyze measures defined independently (perhaps owned by different parts of your organization). Let’s consider two metric views built on the following tables:

sales

sale_id

region

channel

sale_date

amount

cust_id

1

East

web

2023-12-30

100

101

2

East

store

2024-01-02

200

101

3

West

web

2023-12-31

150

102

4

West

store

2024-01-02

50

103

5

North

web

2024-01-03

75

104

tickets

ticket_id

region

severity

c_id

1

East

high

101

2

East

low

101

3

East

low

105

4

West

high

102

5

West

low

103

6

South

low

106

The corresponding metric view definitions are below:

sales_metric_view

tickets_metric_view

You can now report sales and support tickets together by joining the two metric views:

region

sales

sale_count

ticket_count

East

300

2

3

West

200

2

2

The key feature is that this join does not incorrectly duplicate measures. East has two sales and three tickets, producing six joined rows. A regular SUM(s.amount) over those rows returns 900, rather than 300. But MEASURE(s.total_sales) correctly returns 300, because each original sale contributes only once. Similarly, MEASURE(t.ticket_count) counts three tickets, not six joined rows. This holds for one-to-many, many-to-one, and many-to-many joins. Whichever side fans out, the Databricks engine ensures each source row contributes to its measure at most once per group.

Note that North and South are excluded by the inner join, just as in ordinary SQL. MEASURE() protects against join-induced duplication without changing the semantics of the join itself.

You can also combine measures from different metric views in expressions. For example, to calculate support tickets per sale:

East has 1.5 tickets per sale, while West has 1.0.

Filter across metric views

Joins also let you use fields from one metric view to filter measures from another. For example, to report sales by channel, but only for regions with at least one low-severity support ticket:

channel

sales

web

250

store

250

East and West both have low-severity tickets, so their sales qualify. However, East has two matching tickets. A regular SUM(s.amount) across the joined rows would double-count East's sales, returning 350 for web and 450 for store. With MEASURE(), the engine preserves the original measure semantics and correctly returns 250 for each channel.

The same filtering semantics extend to OUTER JOINs, HAVING on evaluated measures, and EXISTS and IN subqueries across metric views.

You could achieve the same result manually using a semi-join or deduplicating the matching regions before joining. But those rewrites require query authors to carefully reason about join cardinality and aggregation for every query. With Unity Catalog Semantics, you get the right answer while writing simple, straightforward queries.

Define multi-fact metric views using query-time joins (Coming soon)

Today, metric view authors can declare multi-fact measures in limited scenarios using definition-time one-to-many joins in the metric view YAML. Soon, support for SQL joins between metric views in the metric view source will enable more flexible multi-fact definitions while preserving relational semantics.

Relationship constraints between metric views

Query-time joins allow agents to safely compose governed metrics in SQL. But agents also need to know how metric views relate to one another. Relationship constraints allow data modelers to capture and govern these relationships directly in Unity Catalog, without prescribing which joins must be performed for a particular analysis.

Foreign key constraints already provide a familiar SQL mechanism for describing relationships between tables. However, they are designed around many-to-one relationships based on key equality, rather than the broader range of relationships needed for semantic modeling.

Relationship constraints address these shortcomings. A relationship constraint is a named, directional link between metric views, with a declared cardinality (one-to-one, many-to-one, or even many-to-many) and a flexible join condition. Agents and BI tools can use these constraints to discover how metric views relate to each other.

Suppose sales_metric_view and tickets_metric_view both expose a customer identifier, and a third metric view, customers_metric_view, holds customer attributes such as segment. The two facts meet at the shared dimension:

A data modeler can add relationship constraints between these metric views to document how they semantically relate to each other:

These relationships will now appear in DESCRIBE TABLE EXTENDED on the metric views and in information_schema.table_constraints. A tool that reads these relationships can discover that sales and tickets connect through customers, and can write the join itself:

Note that no semantic model combining sales, tickets, and customers had to be defined in advance. The individual metric views and their relationships are governed in Unity Catalog, and the agent determines which metric views to join based on the business question. The SQL engine preserves the aggregation semantics of each measure across those joins.

We plan to augment these constraints with more instructions to better address cases such as role-playing dimensions and resolving path ambiguity.

Relationship constraints vs. definition-time joins

Relationships complement the joins a metric view can declare in its own definition.

A definition-time join in the metric view YAML fixes the join at definition time; the engine must use that join path. This is useful when there is exactly one way to relate two datasets, or when the modeler wants to lock in a cross-metric view measure definition using a specific path.

A relationship constraint describes possible joins but defers the choice to the agent or the user at query time. This is useful when there are, or may eventually be, multiple possible ways to relate two datasets, for example, role-playing dimensions (a shipping city and a billing city), a self-relationship (employees and their managers), and even cycles. In these cases, the consuming tool can decide which joins best fit the analytic question at query time.

A SQL foundation for agents and BI tools

Genie Ontology

Genie Ontology already treats metric views as the authoritative definitions of business metrics. With relationship constraints, Genie can also discover how these independently governed metric views relate to one another.

In the sales and support tickets example above, Genie can discover the relationships through the shared customer dimension and generate SQL to analyze sales and support tickets by customer segment. Query-time joins ensure that neither measure is inflated by the join.

As teams publish new metric views and relationships to Unity Catalog, they expand the range of business questions Genie can answer without having to rebuild existing semantic models.

Genie and AI/BI Dashboards

Genie One, Genie Agents, and Genie Code can leverage relationship constraints and query-time joins to answer questions across independently governed metric views. AI/BI Dashboards can also import relationships defined in Unity Catalog, eliminating the need to redefine them for each dashboard. Relationships authored within dashboards can be published back to Unity Catalog, making them reusable across other dashboards and Genie experiences.

Third-party BI integration

BI tools generate SQL for analytic operations such as Top N filters, nested aggregations, and cross-filtering. Integrating with traditional semantic layers often requires BI tools to translate these operations into a model-specific query interface or disable functionality that the interface cannot express. With query-time joins, BI tools can continue generating SQL for these operations while delegating the evaluation of governed measures to Databricks.

For example, the query below, generated by a BI tool, uses a subquery to identify the top two regions by number of sales, then filters the main query to report total sales revenue by channel across those regions. This type of analysis can be difficult or impossible to express through a restricted semantic query interface. With Unity Catalog Semantics, the query runs as written, and the Databricks engine preserves the aggregation semantics of the measures in both the subquery and the main query.

We believe this first-class SQL support makes UC Semantics a uniquely appealing integration target for BI tools. We have started working on integrations with some BI vendors and are looking forward to announcing these in the near future.

If you are a BI vendor, please reach out; we’d love to work with you on integrating UC Semantics into your tools.

What’s next for composable metrics?

Query-time joins and relationships build on what UC Semantics already offers with metric views:

  • window measures for analysis like running totals and period-over-period comparisons
  • semi-additive measures
  • level-of-detail measures for simple two-pass analysis
  • parameters that let a metric view be called like a table-valued function
  • composability via metric views serving as sources for others
  • materialization and pre-aggregation with smart query rewriting for performance and cost

Our next steps continue adding the power of data modeling to SQL. We are working toward declaring ad hoc measures directly in SQL, without requiring a YAML definition for quick explorations or small extensions to existing metric views. We are also working toward rich SQL extensions to control a measure's evaluation context, so that semi-additive logic and period comparisons can be expressed in SQL rather than configured around them.

Our direction is to make governed metrics and relationships reusable across the full range of questions that users and agents ask. By bringing semantic modeling into SQL and Unity Catalog, we can govern metrics independently of the analyses that consume them. Teams define their business metrics once, without having to anticipate every question that will be asked of them.

Continued commitment to openness

Last July, we open-sourced the core metric view and measure reference implementation in Apache Spark™ and Unity Catalog. We are now working to build on top of this foundation and add support for joining measures in SQL. In parallel, we’re excited to be a top contributor to industry standardization efforts such as Apache Ossie (Incubating) and its commitment to portable query semantics.

Getting started

Query-time joins and relationship constraints are in Beta on Databricks Runtime 19 and above and on SQL warehouses. The documentation for joining metric views in SQL, relationships between metric views, and querying metric views walks through the examples in this post, and the TPC-H tutorial builds a complete metric view from sample data.

FAQ’s

How is a metric view different from a semantic model?

A metric view is a Unity Catalog view that behaves like a regular SQL view, with the addition of governed measures. A traditional semantic model takes a different approach: it selects which tables to join based on the requested measures and dimensions, so the underlying set of rows can change from one question to the next. Different BI tools or query interfaces may interpret the same model differently and return different answers.

Metric views avoid this problem by governing the measure logic while preserving standard SQL semantics for everything else. Rather than asking every BI tool to understand a new semantic model, metric views build on a common interface that BI tools already understand: SQL. The metric logic stays consistent regardless of which tool asks the question.

Do I need a primary key for MEASURE() to work across joins?

No. Each measure carries the identity of its source rows, and MEASURE() aggregates over those rows without duplication, regardless of how the query joins them. Two source rows with identical values remain two rows; only the duplication introduced by the join is removed.

What is the difference between definition-time joins in YAML, relationships, and query-time joins?

A join in the metric view's YAML definition fixes the modeling path at definition time, which suits star and snowflake schemas. A relationship is metadata that records how two metric views relate without executing a join. A query-time join composes metric views in SQL for one question. The three work together: define a star via a definition-time join in YAML, describe the graph with relationships, and compose across it at query time.

Can BI tools use metric view joins today?

Yes. BI tools can integrate with metric views through different mechanisms, depending on their query capabilities.

Tools with a pass-through aggregate function can call the governed measure directly. In Tableau, for example, a calculated field that wraps MEASURE() in RAWSQLAGG_REAL sends the measure to Databricks, which evaluates it exactly as defined. The tool keeps generating its own SQL, so it can still leverage features like Top N filters, sets, and two-stage aggregations on top of metric views.

Power BI works through mirroring. Databricks publishes each metric view into a Power BI semantic model as a table with matching Power BI measures in DAX, so reports can join across metric views in that model.

Get the latest posts in your inbox

Subscribe to our blog and get the latest posts delivered to your inbox.

Sign up

View all blogs slice-start id="_gatsby-scripts-1" slice-end id="_gatsby-scripts-1"