More patterns · Open reference architecture

Semantic layer with Spark metric views

Metrics declared in YAML, served over Spark Connect to BI, notebooks and agents

Define revenue once. Every dashboard, notebook and agent gets the same number.

Laptop (Docker)Updated 2026-11-21

In one paragraph

A semantic layer is the set of governed metric and dimension definitions that sit between tables and the tools that query them. In open source Apache Spark, a metric view declares measures and dimensions in YAML over a source table; consumers query it with the MEASURE() function and Spark expands the definition at query time. Served over Spark Connect or JDBC, the same definitions answer dashboards, notebooks and AI agents, so a metric cannot drift between tools.

More patterns

Metrics declared in YAML, served over Spark Connect to BI, notebooks and agents

Sources

Ingestion

Open lakehouse platform

Engine access

Execution

Data foundation

Serving

Teams

Lit boxes are part of this architecture, with the versions its reference repo pins. Switch to Full platform to see every capability. Select any box or team for details. marks a swappable choice.

When to use it

  • Different teams report different numbers for the same metric.
  • You want AI agents to answer questions from governed definitions instead of writing raw SQL.

When to pick something else

  • Spark versions before metric views shipped; the reference demo is verified on Spark 4.2.0.

Walkthrough

How data moves through it

  1. 1

    Declare metrics

    Write measures and dimensions in YAML over a source table.

  2. 2

    Register

    Create the metric view in the catalog.

  3. 3

    Query with MEASURE()

    Clients select dimensions and MEASURE(metric); Spark expands the definition and aggregates at the requested grain.

  4. 4

    Serve everyone

    Dashboards connect over JDBC or Spark Connect, and agents use the same views as tools.

Bill of materials

Components and versions

Versions are the ones pinned in the reference repositories below.
CapabilityComponentRole in this architectureVersionLicense
SourcesSource systemsGold tablesFacts and dimensions to measure
Engine accessSpark Connect sessionsSpark ConnectRemote access for clients and agentsApache-2.0
ExecutionBatch and SQLApache SparkExpands MEASURE() at query time4.2.0Apache-2.0
Data foundationCatalog and credentialsHive Metastoreor Unity Catalog OSSRegisters the metric view in the demoApache-2.0
Data foundationOpen table formatDelta Lakeor Apache IcebergSource tablesApache-2.0
ServingSemantic layerSpark metric viewsYAML measures and dimensionsApache-2.0
ServingDashboards and notebooksApache Supersetor GrafanaDashboards over the metric viewApache-2.0

People and agents

Who works with it

Data engineers

Pipelines that are correct, idempotent and cheap to rerun.

Works with: Batch and SQL, Open table format

AI agents

Tools with clear arguments, a sandbox to write into, fast feedback from dry runs, and version-pinned context.

Works with: Spark Connect sessions, Semantic layer

Analysts and analytics engineers

One definition of each metric, fast SQL, and dashboards that match.

Works with: Semantic layer, Dashboards and notebooks, Batch and SQL

Platform engineers

A platform that is boring to run: deployable from code, observable, with identities for every person, service and agent.

Works with: Catalog and credentials, Spark Connect sessions

Governance and security

Policies that hold in every engine and for every agent, lineage for audits, and least privilege by default.

Works with: Catalog and credentials

Run it

Reference code

lisancao/spark-demosLaptop (Docker)

Demo 01_metrics_views: eight metric view examples, a doctor script and a grammar probe, verified on Spark 4.2.0.

Caveats from the reference repos

  • The reference demo is verified on Spark 4.2.0 and awaits official Spark 4.3 images for re-verification.

Industry lenses

Where this architecture shows up

Each card opens the board with that industry's sources. Full industry pages: Banking, Manufacturing, Retail and e-commerce.

Answers

Frequently asked questions

Does open source Spark have a semantic layer?
Yes. Spark metric views declare measures and dimensions in YAML over a table, and queries use the MEASURE() function to evaluate them.
Why give AI agents a semantic layer?
Because an agent querying metric views uses the governed definition of each metric instead of inventing its own SQL, so its answers match the dashboards.