variables/

On this page

Variables: runtime configuration loaded from config/variables/

Phase: Post-catalog | Order: 6 | Required: No

Variables define pipeline configuration as SQL. Access via getvariable('name') in SQL or getvariable("name") in Starlark.

Directory Structure

FileScopeWhen Loaded
config/variables/constants.sqlConstantsOnce at session init
config/variables/global.sqlGlobalOnce at session init (can use subqueries)
config/variables/local.sqlPer-modelBefore each model’s validation step

Constants

SET VARIABLE default_currency = 'SEK';
SET VARIABLE vat_rate = 0.25;
SET VARIABLE alert_amount_threshold = 1000000;

Global

SET VARIABLE total_models = (
    SELECT COUNT(DISTINCT commit_extra_info->>'model')
    FROM snapshots()
    WHERE commit_extra_info->>'model' IS NOT NULL
);

Per-Model

-- current_model is set by the runtime before this file loads
SET VARIABLE prev_model_snapshot = COALESCE(
  (SELECT snapshot_id FROM (
    SELECT snapshot_id, ROW_NUMBER() OVER (ORDER BY snapshot_id DESC) AS rn
    FROM snapshots()
    WHERE LOWER(commit_extra_info->>'model') = LOWER(getvariable('current_model'))
  ) WHERE rn = 2), 0);

Built-in Variables

VariableDescription
ondatra_run_timeRun start time (UTC)
ondatra_load_idUnique run identifier
curr_snapshotCurrent DuckLake snapshot ID
prev_snapshotPrevious snapshot ID (for CDC)
dag_start_snapshotSnapshot at DAG start
current_modelTarget name of the current model (set per-model)

For DuckDB variable syntax, see the DuckDB variable documentation.