Back to Building a Real dbt Project

Sources and the Staging Layer

Where the work actually starts: defining sources, writing stg_ models, the conventions every team follows. FIND_VIDEO: search 'dbt staging layer sources tutorial' — recommended channel: dbt Labs / Kahan Data Solutions. Aim for 10 min or under.

10 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. DBT Source Definition — Introduces sources as the raw entry point for dbt transformations loaded by external ETL tools.
  2. Source Configuration Mechanics — Explains the YAML structure and file location used to define raw data sources declaratively.
  3. Creating Raw Warehouse Data — Demonstrates executing DDL and DML in Snowflake to simulate external raw data ingestion.
  4. Source YAML Implementation — Configures the source YAML file with database, schema, table mappings, and column metadata.
  5. Staging Model with source() — Builds a staging SQL model using the Jinja source function to query raw data.
  6. source() vs ref() Distinctions — Differentiates referencing external raw data with source versus internal models with ref.
  7. Executing the Transformation Pipeline — Runs the dbt project to validate DAG lineage and materialize staging and mart models.
PDF notes

Frequently asked questions

Where should source YAML files be stored in a dbt project?

Place source YAML files anywhere within the models directory, commonly organized under models/staging/<source_name>/.

What happens if an upstream raw table name changes in the data warehouse?

Update the table name in the source YAML file once, and all staging models using source() update automatically upon compilation.

Can you run tests directly on raw sources?

Yes, dbt allows freshness checks and generic data tests defined directly on raw tables in the source YAML configuration.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.