|
| 1 | +# HYF Data Track — Week 10 Practice Exercises |
| 2 | + |
| 3 | +Four exercises that consolidate Week 10 (dbt Core: SQL transformations as a tested, documented, version-controlled project). Each exercise targets one skill from the content chapters. Work through them in order: Exercise 1 is a prerequisite for the `fct_trips` mart, and later exercises assume the project state from Exercises 1–3. |
| 4 | + |
| 5 | +These exercises require your Week 10 dbt project (set up in Chapter 2) running against the shared Azure PostgreSQL instance. They are not standalone: you copy the provided SQL files into your project and run dbt commands. |
| 6 | + |
| 7 | +## Layout |
| 8 | + |
| 9 | +| Folder | Skill | dbt command to verify | |
| 10 | +|--------|-------|----------------------| |
| 11 | +| `exercise_1` | Macros and computed columns for `stg_trips` | `dbt run --select stg_trips` | |
| 12 | +| `exercise_2` | Write and run a singular test | `dbt test --select test_type:singular` | |
| 13 | +| `exercise_3` | Debug a broken `ref()` | `dbt compile --select fct_trips` | |
| 14 | +| `exercise_4` | Propagate a column change from staging to mart | `dbt run --select +fct_trips` | |
| 15 | + |
| 16 | +## Folder structure |
| 17 | + |
| 18 | +```text |
| 19 | +week-10/ |
| 20 | + exercise_1/ |
| 21 | + safe_divide.sql -- copy to macros/safe_divide.sql |
| 22 | + stg_trips.sql -- copy to models/staging/stg_trips.sql |
| 23 | + README.md |
| 24 | + solutions/ |
| 25 | + safe_divide.sql |
| 26 | + stg_trips.sql |
| 27 | + exercise_2/ |
| 28 | + assert_fare_amount_non_negative.sql -- copy to tests/ |
| 29 | + README.md |
| 30 | + solutions/ |
| 31 | + assert_fare_amount_non_negative.sql |
| 32 | + exercise_3/ |
| 33 | + fct_trips_broken.sql -- copy to models/marts/fct_trips.sql (overwrites) |
| 34 | + README.md |
| 35 | + solutions/ |
| 36 | + fct_trips.sql |
| 37 | + exercise_4/ |
| 38 | + stg_trips.sql -- copy to models/staging/stg_trips.sql |
| 39 | + fct_trips.sql -- copy to models/marts/fct_trips.sql |
| 40 | + README.md |
| 41 | + solutions/ |
| 42 | + stg_trips.sql |
| 43 | + fct_trips.sql |
| 44 | +``` |
| 45 | + |
| 46 | +## How to run |
| 47 | + |
| 48 | +These are dbt model, macro, and test files. Copy each file to the path shown in the exercise README, then run the dbt command shown in the table above. You need your Week 10 dbt project connected to the shared Azure PostgreSQL and `PG_PASSWORD` set in your environment. |
| 49 | + |
| 50 | +No `requirements.txt` is needed here: your dbt project already has `dbt-core` and `dbt-postgres` installed from Chapter 2. |
| 51 | + |
| 52 | +## Reference solutions and spoiler discipline |
| 53 | + |
| 54 | +Each `exercise_N/solutions/` folder holds the answer with `-- WHY` comments explaining the non-obvious choices. Time-box yourself to 15–20 minutes on each exercise before peeking. When you do open a solution, read the WHY notes: the reasoning is the teaching content. |
0 commit comments