For the complete documentation index, see llms.txt. This page is also available as Markdown.

Data model

Write the transforms that turn raw inputs into reliable output tables.

A data model is the transform: the SQL or Python that turns raw input into something useful. Each model file produces one physical table or view. Vulcan manages the run order, versioning, and safe deployment for you.

This is where you add the meaning the raw data doesn't have yet: joins, business rules, aggregates.

A Vulcan model is a .sql file with two parts:

  1. A MODEL block declaring the name, kind, schedule, grain, description, and assertions.

  2. A SELECT query with the transformation logic.

Vulcan reads dependencies from your FROM and JOIN clauses, so you never configure a run order by hand. If silver.fct_daily_sales selects from bronze.orders, Vulcan builds bronze.orders first.

The shape

MODEL (
  name silver.fct_daily_sales,
  kind FULL,
  cron '*/15 * * * *',
  grains (order_date, region_id, customer_id, product_id),
  description 'Daily sales fact by date, customer, product, and region.',
  assertions (
    not_null(columns := (order_date, total_revenue))
  )
);

SELECT
  DATE_TRUNC('day', o.order_date)::TIMESTAMP AS order_date,
  c.region_id,
  o.customer_id,
  i.product_id,
  r.region_name,
  p.category,
  SUM(i.quantity * i.unit_price) AS total_revenue
FROM bronze.orders AS o
INNER JOIN bronze.customers AS c ON o.customer_id = c.customer_id
INNER JOIN bronze.regions AS r ON c.region_id = r.region_id
INNER JOIN bronze.order_items AS i ON o.order_id = i.order_id
INNER JOIN bronze.products AS p ON i.product_id = p.product_id
GROUP BY 1, 2, 3, 4, 5, 6;

order_date is cast to TIMESTAMP, not DATE, because a metric's ts column must be a timestamp (see Metrics). The SELECT outputs every grains column, plus the region_name and category dimensions the semantic model exposes.

Model names follow schema.table_name. The grains property declares the columns that uniquely identify a row, written as a parenthesized tuple: a single grain is grains (order_id), a composite grain is grains (customer_id, order_date).

Document and tag individual columns directly on the MODEL block with column_descriptions, column_tags, column_terms, and column_classifications, instead of inline SQL comments.

Bronze, silver, gold

orders-analytics organizes its 12 models into three layers, so dependencies read top to bottom:

  • bronze copies a source table close to its raw shape

  • silver joins bronze tables and applies business logic, like the silver.fct_daily_sales model above

  • gold reshapes silver for one specific analytics use case

Each layer only reads from the layer above it. Vulcan resolves that order from the FROM and JOIN clauses, so you never declare it by hand.

Bronze stays close to the source and carries the assertions that guard what every later layer will trust:

Gold consumes silver and shapes the result for one consumer-facing question, such as scoring customers by recency, frequency, and monetary value:

The real model buckets each score into 5 tiers and assigns one of 9 segment labels. This is the same CASE-driven pattern, just condensed.

Choose a kind

The kind decides how the model materializes. It's the most important choice you make for each model.

Kind
Rebuilds each run
Best for

VIEW (default)

No, runs on demand

Lightweight transforms, always-fresh data

FULL

Yes, full rebuild

Small or aggregate tables

INCREMENTAL_BY_TIME_RANGE

Partial, by time interval

Time-series: events, logs, transactions

INCREMENTAL_BY_UNIQUE_KEY

Partial, upsert by key

Dimension and current-state tables

INCREMENTAL_BY_PARTITION

Partial, by partition key

Datasets reprocessed by group

INCREMENTAL_UNMANAGED

Partial, append only

Append-only tables with no deduplication

SEED

Only when the CSV changes

Static reference data

SCD_TYPE_2_BY_TIME / _BY_COLUMN

Partial, history tracking

Slowly changing dimensions

EMBEDDED

Never, no table created

Reusable SQL snippet inlined as a subquery into referencing models

MANAGED

No, Snowflake refreshes it

Snowflake Dynamic Tables (Snowflake only)

EXTERNAL

Never, metadata only

Describing external tables your models query

orders-analytics uses FULL for all 12 SQL models, since the data volume is small, plus one SEED model. Reach for an incremental kind when a table grows continuously and a full rebuild gets too slow.

Python models can't use VIEW, SEED, EMBEDDED, or MANAGED: those kinds are SQL-only.

For the full kind reference, see References → Vulcan → Model → Kinds.

SQL or Python

Most models are SQL. When a transform needs logic that SQL can't express, write a Python model instead, using the @model decorator and an ExecutionContext.

You can mix both in one project: SQL for set-based work, Python where it pays off. Reusable logic goes into macros, which you call inline as @macro_name().

Last updated

Was this helpful?