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.ymlandmodels.ymlaccept- How to write a staging model and a mart model
- When to pick
view,table, orincremental- How
ref()andsource()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:
| Field | Level | Notes |
|---|---|---|
name | source | Logical name you use in source('name', 'table') |
schema | source | Warehouse database that holds the raw landings |
tables[].name | table | Key you pass to source() |
tables[].identifier | table | Physical table name if it differs from name |
tables[].loaded_at_field | table | Column freshness checks read |
tables[].freshness.warn_after | table | { count, period } where period is minute, hour, day, or week |
tables[].freshness.error_after | table | Same 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. Cheapviewmaterialization by default. - Mart models join staging models into the business facts and dimensions your dashboards and metrics query. Usually materialized as
tableorincremental.
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:
| Field | Type | Default | Notes |
|---|---|---|---|
name | string | required | Must match the .sql file name |
description | string | "" | Shown in the model picker and used by AI Q&A |
config.materialized | enum | view | view, table, or incremental |
config.schema | string | marts | Warehouse database Goni writes into |
config.tags | list | [] | 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 insources.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
viewrewrites 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.tablematerializes 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.incrementalappends only new rows on subsequent runs, defined by anis_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.
Related
Last updated