How divinesamofficial/snowflake-elt-pipeline-with-dbt-and-airflow works
Purpose and Entrypoints
This is a Snowflake ELT example: dbt transforms TPCH order data in Snowflake, while Apache Airflow schedules and executes the dbt workflow. The operational entrypoint is the Airflow DAG at dbt-dag/dags/dbt_dag.py. The standalone dbt project is rooted at data_pipeline/dbt_project.yml; a deployable copy is embedded under dbt-dag/dags/dbt/data_pipeline/dbt_project.yml.
Runtime and Deployment Boundary
Airflow is containerized through dbt-dag/Dockerfile, with Python/Airflow dependencies in dbt-dag/requirements.txt and dbt package requirements in dbt-dag/packages.txt. The DAG-local dbt project places transformation code where the Airflow runtime can invoke it. Snowflake is the external warehouse, including its sample TPCH dataset as the source system.
Source and Staging Layer
dbt declares TPCH source relations in data_pipeline/models/staging/tpch_sources.yml. Staging models normalize the primary orders and line-item inputs:
• data_pipeline/models/staging/stg_tpch_orders.sql
• data_pipeline/models/staging/stg_tpch_line_items.sql
This boundary separates Snowflake sample/source tables from internally modeled relations and establishes dbt lineage for downstream execution.
Transformation and Mart Layer
Order and line-item transformations progress from reusable intermediate models into an order fact mart:
• data_pipeline/models/marts/int_order_items.sql
• data_pipeline/models/marts/int_order_items_summary.sql
• data_pipeline/models/marts/fct_orders.sql
The expected flow is source orders/line items → staging models → item-level intermediate data → aggregated item summary → fct_orders. dbt dependency references determine model build order.
Shared Business Logic
Pricing/discount calculation is centralized as a dbt macro in data_pipeline/macros/pricing.sql, rather than duplicated across models. Models that require pricing logic can compile that macro into Snowflake SQL. The same macro is carried in the Airflow-executed project at dbt-dag/dags/dbt/data_pipeline/macros/pricing.sql.
Data Quality Gates
dbt applies schema/generic checks through data_pipeline/models/marts/generic_tests.yml and custom SQL assertions through:
• data_pipeline/tests/fct_orders_date_valid.sql
• data_pipeline/tests/fct_orders_discount.sql
These tests are a quality boundary around the final order mart, intended to fail dbt/Airflow execution when date or discount assumptions are violated.
Orchestration Flow
dbt-dag/dags/dbt_dag.py defines the Airflow control plane: it schedules the dbt project located beneath dbt-dag/dags/dbt/data_pipeline, invokes dbt work, and exposes run status through Airflow. The repository therefore has two copies of dbt assets: data_pipeline/ is the development project, while dbt-dag/dags/dbt/data_pipeline/ is the DAG-runtime payload; changes must remain synchronized unless deployment packaging is changed.
Main entry points: fct_orders.sql Orders fact mart · int_order_items.sql Order items · tpch_sources.yml TPCH source declarations · Dockerfile Airflow image
Components 18
Airflow deployment
- Airflow image
dbt-dag/Dockerfile - Airflow dependencies
dbt-dag/requirements.txt - dbt dependencies
dbt-dag/packages.txt - dbt workflow DAG · Schedules and runs the embedded dbt project.
dbt-dag/dags/dbt_dag.py
dbt development project
- TPCH source declarations
data_pipeline/models/staging/tpch_sources.yml - Staged orders
data_pipeline/models/staging/stg_tpch_orders.sql - Staged line items
data_pipeline/models/staging/stg_tpch_line_items.sql - Pricing logic · Centralizes pricing and discount calculation.
data_pipeline/macros/pricing.sql - Order items
data_pipeline/models/marts/int_order_items.sql - Item summary
data_pipeline/models/marts/int_order_items_summary.sql - Orders fact mart
data_pipeline/models/marts/fct_orders.sql - Mart schema tests
data_pipeline/models/marts/generic_tests.yml - Order date assertion
data_pipeline/tests/fct_orders_date_valid.sql - Discount assertion
data_pipeline/tests/fct_orders_discount.sql - Development dbt project · Source project maintained outside the Airflow runtime.
data_pipeline/dbt_project.yml
Snowflake warehouse
- TPCH source tables
DAG dbt payload
- Embedded dbt project · Deployable copy invoked by Airflow.
dbt-dag/dags/dbt/data_pipeline/dbt_project.yml - Embedded pricing logic
dbt-dag/dags/dbt/data_pipeline/macros/pricing.sql
Connections 18
- Airflow dependencies → Airflow image: installed in
- dbt dependencies → Airflow image: installed in
- Airflow image → dbt workflow DAG: runs
- dbt workflow DAG → Embedded dbt project: invokes
- Development dbt project → Embedded dbt project: synchronized as
- Pricing logic → Embedded pricing logic: copied to
- Embedded dbt project → Embedded pricing logic: includes
- TPCH source tables → TPCH source declarations: declared by
- TPCH source declarations → Staged orders: feeds
- TPCH source declarations → Staged line items: feeds
- Staged orders → Order items: builds
- Staged line items → Order items: builds
- Pricing logic → Order items: compiled into
- Order items → Item summary: aggregates to
- Item summary → Orders fact mart: builds
- Orders fact mart → Mart schema tests: validated by
- Orders fact mart → Order date assertion: validated by
- Orders fact mart → Discount assertion: validated by