Data Analyst / Engineer · Focus area 2: Data warehousing
DT7: dbt: transformations as tested code
Goal: build a warehouse's models with dbt: SQL files that know their dependencies, tests that run on every build, documentation that stays next to the code, materialisations that fit each table, and a workflow where every change is reviewed and checked.
You'll need: DT5, DT6, Module 9 (Introduction to Git), Module 56 (Advanced Queries), Module 71 (CI/CD), and the SabziSathi practice kit.
Where this is used: many companies, from startups to large banks, keep their warehouse's SQL in a dbt project in Git. Analysts and engineers change it through pull requests, and every change is built and tested before it reaches a dashboard.
How it differs: SQL pasted into a BI tool or a scheduled query is hard to review, test or reuse. dbt treats SQL like software: versioned, tested, documented and built in order.
Time: reading about 2½ hours · practice (the Try it tasks) about 3 hours · assignment about 3 hours.
Lessons
- 1Models, `ref` and `source`Reading 15–25 minutes, plus practice✓
- 2Tests that run on every buildReading 15–25 minutes, plus practice✓
- 3Documentation and lineageReading 15–25 minutes, plus practice✓
- 4Materialisations: view, table, incrementalReading 15–25 minutes, plus practice✓
- 5dbt in a teamReading 15–25 minutes, plus practice✓
🛠️Assignment: SabziSathi's dbt project, tested and documented
This is the third part of Project 2.
- Declare every pipeline table as a source, with
loaded_at_fieldand freshness onorder_linesand tests on the source keys. - Add generic tests:
uniqueandnot_nullon the fact's grain and dimension keys,accepted_valueson status and store, andrelationshipsfrom the fact to every dimension. - Add a singular test that reconciles
mart_daily_saleswith the fact table. - Make
fct_order_linesincremental with aunique_keyand a 3-day look-back. - Write descriptions for every mart model and column, and generate the docs site.
Self-check before you finish:
- [ ]
dbt buildpasses with every test, and you've seen at least one test fail on purpose. - [ ] Reloading a day and rebuilding gives the same totals.
- [ ]
dbt source freshnesspasses after a load. - [ ] No connection detail or salt is in a committed file.
- [ ]
pytest tests/test_warehouse.pypasses all 10.
✅Module check
Explain in a few sentences, in your own words:
Why build a warehouse with dbt instead of scheduled queries?
Show a good answer
A good answer mentions: one select per model linked with ref and source, so dbt builds in dependency order; macros for shared
logic; generic and singular tests on grain, keys and business rules, run on every build; descriptions and lineage kept with the code;
views, tables and incremental models chosen for each case, with unique keys and look-backs; development environments, pull requests and
CI; freshness checks in the scheduled job; and secrets from environment variables.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
