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.
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
How agents, apps and people reach compute: a client session per identity.
Execution
Spark's execution modes, plus engines that read the same tables.
Data foundation
Open tables in a governed catalog, on storage you own.
Serving
Teams
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
Declare metrics
Write measures and dimensions in YAML over a source table.
- 2
Register
Create the metric view in the catalog.
- 3
Query with MEASURE()
Clients select dimensions and MEASURE(metric); Spark expands the definition and aggregates at the requested grain.
- 4
Serve everyone
Dashboards connect over JDBC or Spark Connect, and agents use the same views as tools.
Bill of materials
Components and versions
| Capability | Component | Role in this architecture | Version | License |
|---|---|---|---|---|
| SourcesSource systems | Gold tables | Facts and dimensions to measure | ||
| Engine accessSpark Connect sessions | Spark Connect | Remote access for clients and agents | Apache-2.0 | |
| ExecutionBatch and SQL | Apache Spark | Expands MEASURE() at query time | 4.2.0 | Apache-2.0 |
| Data foundationCatalog and credentials | Hive Metastoreor Unity Catalog OSS | Registers the metric view in the demo | Apache-2.0 | |
| Data foundationOpen table format | Delta Lakeor Apache Iceberg | Source tables | Apache-2.0 | |
| ServingSemantic layer | Spark metric views | YAML measures and dimensions | Apache-2.0 | |
| ServingDashboards and notebooks | Apache Supersetor Grafana | Dashboards over the metric view | Apache-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
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.
Related architectures
All architecturesMore patterns
Arrow-native serving
Arrow Flight SQL and Spark Connect clients over lakehouse tables
Platform
The agentic lakehouse
Omnigent and MLflow over sandboxed Spark Connect sessions, on Iceberg and Unity Catalog
Platform
The open lakehouse on a laptop
Spark 4.3, Apache Iceberg, Unity Catalog, Kafka, Airflow, MLflow and an agent, in Docker
