Semantic layer

Semantic layer overview

How Goni's dbt-like YAML (sources, models, metrics, tests) compiles to ClickHouse SQL, materializes into the warehouse, and powers metrics + AI Q&A.

What this page does for you

The one-sentence version: Goni’s semantic layer is a git-native, dbt-like YAML project that compiles to ClickHouse SQL and materializes views, tables, and materialized views directly into your warehouse.

You’ll learn:

  • How the four YAML files fit together
  • The compile -> materialize -> lineage -> tests loop
  • What lands in the warehouse and where
  • How UI-authored overlays layer on top of repo YAML

The four files

A semantic project is a directory of YAML plus optional Jinja-templated SQL files. The canonical layout:

your-project/
  sources.yml     # external tables in the raw layer, freshness, source tests
  models.yml      # per-model materialization + target schema
  models/*.sql    # Jinja+SQL bodies, referenced by name from models.yml
  metrics.yml     # metric definitions the API and AI Q&A load on boot
  tests.yml       # column-level invariants (not_null, unique, accepted_values, ...)

sources.yml names raw landings (schema raw) and declares freshness contracts against a loaded_at_field. models.yml names each model and sets config: { materialized: view | table | materialized_view, schema: staging | marts_semantic | ... }. metrics.yml declares reusable measures with dimensions, filters, and a time grain. tests.yml attaches column-level tests at the source, staging, and mart layer.

The compile -> materialize -> lineage -> tests loop

Goni’s semantic runner has four stages:

  • compile - render SQL for every model, no warehouse writes.
  • build - compile plus materialize plus emit lineage.
  • test - run schema tests against the warehouse.
  • all - build plus test (the usual).

During compile, each ref('other_model') is rewritten into a fully-qualified schema.name reference, and models are ordered by their dependencies before anything runs against the warehouse.

Materialize then walks that dependency order and drops + recreates each object in the warehouse:

  • view -> DROP VIEW ...; CREATE VIEW <schema>.<name> AS <sql>
  • table -> DROP TABLE ...; CREATE TABLE <schema>.<name> ENGINE = MergeTree ORDER BY tuple() AS <sql> (override with {{ config(order_by=...) }})
  • materialized_view -> creates a target table plus an MV pointing at it

You can compile through the workbench and see which models rebuilt and when. The lineage step emits a node-and-edge graph that feeds the Audit and lineage view. Finally, the tests step runs each declared invariant as a SELECT count(*) FROM ... WHERE <invariant is violated> and reports ok / warn / error.

What lands in the warehouse

The example project uses a three-tier layout that matches what most Goni customers will operate:

  • raw - landings from connectors (see Connectors). Immutable append. Freshness is measured here via _goni_ingested_at.
  • staging - 1:1 cleanups of raw tables, defaulted to view so they are always fresh and free to rebuild.
  • marts_semantic - joined + shaped tables (dim_*, fct_*, agg_*), defaulted to table because they are queried often and rebuild is expensive.

That layering is a convention, not a hard rule - any model can pick any schema and any materialized mode from models.yml.

ref() and cross-model references

Inside a model’s SQL body, {{ ref('other_model') }} rewrites into the fully-qualified schema.name reference and records an edge in the dependency graph. That graph drives topological ordering during build and feeds the lineage view. See Sources and models for the full pattern with worked examples.

User overlays: UI-authored changes on top of your YAML

Your git-tracked YAML is the ground truth, but the API exposes an overlay layer so UI-authored edits do not require a git commit:

GET    /api/metrics             # list metric signatures (base + overlay merged)
PUT    /api/metrics/{name}      # upsert a user metric
DELETE /api/metrics/{name}      # remove a user metric

GET    /api/models              # list model signatures
GET    /api/models/{name}       # read a user model
PUT    /api/models/{name}       # upsert a user model
DELETE /api/models/{name}       # remove a user model

Overlays persist in the control plane (see Architecture and the two data planes) and merge over base YAML at read time. Base definitions still win on conflict unless the overlay explicitly names the same object. Access to both endpoint families is default-deny RBAC - see Access control.

Note: the AI Q&A layer reads the merged catalog, so a metric you add through PUT /api/metrics/{name} becomes askable immediately without a redeploy.

Overlay retention today

Overlay records live indefinitely in the control plane. There is no server-side TTL on user metric or user model rows, so an overlay written once persists until a DELETE /api/metrics/{name} or DELETE /api/models/{name} call removes it. Deletions are hard deletes rather than tombstones and take effect on the next catalog read.

Treat overlays as durable artifacts and clean them up explicitly when they are no longer needed. Every overlay write and delete lands in the audit log with the caller’s identity, so review is straightforward - see Audit and lineage.

Last updated