dbt compile converts model SQL and Jinja into executable SQL files, letting you inspect, test, and debug transformations before execution.
dbt compile is a CLI command that renders Jinja-templated model files into raw SQL, stores them in the target/compiled
directory, and performs macro expansion without running the queries.
Running dbt compile surfaces syntax errors early, accelerates code review, and feeds downstream linters or query editors like Galaxy that can preview compiled SQL instantly.
dbt parses dbt_project.yml
, loads macros, resolves ref()
and source()
calls, then writes one file per node with the database-specific SQL ready for execution.
Use dbt compile before committing code, inside CI pipelines, or when exploring model dependencies without touching the warehouse.
Automate the command in pre-commit hooks, compile only changed models with dbt compile --select state:modified+
, and review generated SQL in Galaxy or your IDE.
Inspect the traceback, verify macro arguments, ensure valid Jinja syntax, and re-run with --debug
for verbose logs that pinpoint the failing node.
steps:
- name: Compile dbt models
run: |
pip install dbt-core dbt-bigquery
dbt deps
dbt compile --profiles-dir profiles --warn-error
Open the target/compiled
directory in Galaxy’s desktop app to execute or share the rendered SQL without altering your dbt repo.
.
dbt compile forms the feedback loop between code and data, allowing engineers to validate transformations offline. Early detection of errors reduces warehouse costs and shortens development cycles. Reviewing compiled SQL also enforces governance by exposing the exact statements that will run in production.
It only needs metadata access for adapters that resolve relations; no data is read or written.
Yes, use dbt compile --select my_model
or any selector syntax.
Galaxy can open compiled SQL for interactive testing, formatting, and team endorsement without altering dbt sources.
Usually faster because it skips warehouse execution, though large macro graphs can still take time.