models/builds/ directory.
File structure
The logic of the build model can be written in SQL or Python. Optionally, the metadata of the build model (such as column descriptions) can be specified in a YAML file with the same name.SQL build models
SQL build models use the DuckDB SQL dialect and support Jinja templating.Example SQL model
models/builds/build_transactions.sql
Available Jinja variables
The following variables are available in SQL build models:| Variable | Description |
|---|---|
proj_vars | Dictionary of project variables from squirrels.yml |
env_vars | Dictionary of environment variables |
ref(model_name) | Macro that returns the table name for the referenced model |
The ref() macro
The ref() macro is used to reference other models. It can reference:
- Sources (with
load_to_vdl: trueor DuckDB connection type) - Seeds
- Other build models
Python build models
Python build models define amain() function that receives a BuildModelArgs object and returns a Polars LazyFrame (or DataFrame).
Example Python model
models/builds/build_transactions.py
YAML configuration
An optional YAML file with the same name provides additional configuration for the model.models/builds/build_transactions.yml
Configuration fields
A description of the model for documentation purposes.
How the model is stored in the VDL. Options are
TABLE or VIEW.Python models are always materialized as tables regardless of this setting.
List of model names this build model depends on. Optional for SQL models (derived from
ref() calls), but required for Python models.Column metadata definitions as a list.
Materialization
Build models can be materialized as either tables or views in the VDL:| Materialization | Description |
|---|---|
TABLE | Data is stored physically. Faster for repeated queries, but takes more storage. |
VIEW | Data is computed on-demand. Saves storage, but slower if queried multiple times. |
Python build models are always materialized as tables, regardless of the
materialization setting. This is because DuckDB only supports view definitions in SQL, not Python.Best practices
-
Use descriptive names: Prefix build model names with
build_to distinguish them from other model types. -
Declare dependencies explicitly: Even though SQL models can auto-detect dependencies via
ref(), explicitly listing them in YAML helps with documentation. -
Use pass_through for inherited columns: When a column passes through unchanged from an upstream model, use
pass_through: trueto automatically inherit its metadata. -
Choose materialization wisely: Use
TABLEfor models that are queried frequently or have expensive computations. UseVIEWfor simple transformations or infrequently accessed models.
Related pages
- Sources - Configure source tables from external databases
- Seeds - Static CSV data files
- Federate models - Dynamic models that run at query time
- Dbview models - Models that run on external databases
- BuildModelArgs - API reference for Python build model arguments
- sqrl build - CLI reference for
sqrl build