Semantic layer

Sources and models

Reference for sources.yml and models.yml: schema, materialization strategies, ref() resolution, lineage, and the user-layer merged view.

What this page does for you

Sources and models are the two building blocks of your semantic layer in Goni. Sources declare the raw tables Goni ingested for you. Models are the SQL you author on top of them. This page is the reference for both, including the YAML shape you write, the materialization options you can pick, and how ref() and source() wire everything together.

You’ll learn:

  • The exact keys sources.yml and models.yml accept
  • How to write a staging model and a mart model
  • When to pick view, table, or incremental
  • How ref() and source() resolve in your SQL
  • How to compile your project

If you are coming from dbt, the shapes below will look familiar. Goni’s semantic layer is dbt-like: it uses the same core concepts (sources, models, ref(), materialization), so most patterns translate directly.

Sources

A source is a raw table that Goni already landed in your warehouse. Every connector you configured in Connectors and every streaming subscription you set up publishes into a source table. You declare those tables in sources.yml so the semantic layer knows what they are and where they live.

version: 2

sources:
  - name: acme
    description: >
      Acme Cloud SaaS, ingested from Postgres via the source connector.
    schema: raw
    tables:
      - name: acme_customers
        identifier: acme_customers
        description: Customer master, roughly 500 rows.
        loaded_at_field: _goni_ingested_at
        freshness:
          warn_after:  { count: 3,  period: hour }
          error_after: { count: 12, period: hour }

Fields you can set:

FieldLevelNotes
namesourceLogical name you use in source('name', 'table')
schemasourceWarehouse database that holds the raw landings
tables[].nametableKey you pass to source()
tables[].identifiertablePhysical table name if it differs from name
tables[].loaded_at_fieldtableColumn freshness checks read
tables[].freshness.warn_aftertable{ count, period } where period is minute, hour, day, or week
tables[].freshness.error_aftertableSame shape as warn_after

Freshness thresholds are how you tell Goni when raw data is late. See Tests, freshness, and data quality for how they surface in the UI and in alerts.

Models

A model is a SELECT query you write that Goni materializes into your warehouse. Each model is a .sql file plus an entry in models.yml with its config. The name in models.yml must match the file name of the SQL.

Goni encourages a two-layer pattern that most analytics teams already use:

  • Staging models clean up one raw source table each. One stg_ file per source table. Cheap view materialization by default.
  • Mart models join staging models into the business facts and dimensions your dashboards and metrics query. Usually materialized as table or incremental.
version: 2

models:
  - name: stg_customers
    description: 1:1 cleanup of the raw customers source
    config: { materialized: view,  schema: staging }

  - name: fct_subscriptions
    description: Subscription fact with joined customer attributes and ARR
    config: { materialized: table, schema: marts }

  - name: agg_weekly_arr
    description: Weekly running ARR by country
    config: { materialized: incremental, schema: marts }

Config fields:

FieldTypeDefaultNotes
namestringrequiredMust match the .sql file name
descriptionstring""Shown in the model picker and used by AI Q&A
config.materializedenumviewview, table, or incremental
config.schemastringmartsWarehouse database Goni writes into
config.tagslist[]Free-form labels you can filter on

Writing SQL: ref() and source()

Inside a .sql file you never hardcode a table name. You reference other models and sources through two functions:

  • {{ source('acme', 'acme_customers') }} resolves to the raw source table you declared in sources.yml.
  • {{ ref('stg_customers') }} resolves to another model in your project.

Both functions build the dependency graph for you. Goni compiles models in the right order and refuses to run a project with a cycle, so you can move models around without hand-managing the sequence.

A staging model that reads from a source:

-- stg_customers.sql
SELECT
  id                        AS customer_id,
  lower(trim(email))        AS email,
  country_code              AS country,
  created_at                AS signed_up_at
FROM {{ source('acme', 'acme_customers') }}
WHERE deleted_at IS NULL

A mart model that joins two staging models:

-- fct_subscriptions.sql
{{ config(materialized='table', schema='marts') }}

SELECT
  s.subscription_id,
  s.customer_id,
  c.country,
  s.plan,
  s.mrr,
  s.mrr * 12 AS arr,
  s.started_at,
  s.canceled_at
FROM {{ ref('stg_subscriptions') }} s
LEFT JOIN {{ ref('stg_customers') }} c
  ON c.customer_id = s.customer_id

You can set config inline at the top of a SQL file as shown above. Inline config wins over the YAML entry for that model.

Materialization: which one to pick

  • view rewrites the SELECT into a warehouse view. Zero storage cost and always fresh, but every downstream query pays the compute. Use for staging models and any lightweight passthrough.
  • table materializes the query into a real warehouse table on every compile. Fast to query, costs storage, rebuilt from scratch each run. Use for marts you query repeatedly and can afford to rebuild.
  • incremental appends only new rows on subsequent runs, defined by an is_incremental() guard in your SQL. Use for large fact tables where a full rebuild is wasteful.

Rule of thumb: staging is a view, marts are tables, big append-only facts are incremental.

Compiling your project

Open the semantic layer workspace and click Compile. Goni parses your YAML, resolves ref() and source(), materializes each model in dependency order, runs tests, and emits column-level lineage. Errors surface inline against the file that broke.

Every compile is tracked, so you can see which models ran, how long each took, row counts, and the exact SQL that shipped. This history is what the lineage graph and audit trail join against, covered in Audit and lineage.

Coming from dbt

If you already run dbt, the mental model transfers directly. sources.yml, models.yml, ref(), source(), {{ config(...) }}, and the staging plus marts convention all work the same way. Lift your models/ folder into Goni, connect your sources, and click Compile. Anything Goni cannot compile shows up in the errors panel with a link to the file.

Last updated