|
1 | | -# HYF Data Track — Week 10 Practice Exercises |
| 1 | +# HYF Data Track — Week 10 Practice |
2 | 2 |
|
3 | | -Five 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. |
| 3 | +The Week 10 dbt drills no longer live here. They were loose SQL files with no dbt project around them, so they could not actually be run: you had to mentally graft them into your own project. They now live as **branches in the Week 10 reference repo**, each starting from the finished project so `dbt compile` and `dbt build` work for real. |
4 | 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. |
| 5 | +## Where they went |
6 | 6 |
|
7 | | -## Layout |
| 7 | +Clone the reference repo once, then `git switch` to an exercise branch and follow its `EXERCISE.md`. Compare your work against the matching `-solution` branch. |
8 | 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 | | -| `exercise_5` | Add the four generic tests (`not_null`, `unique`, `accepted_values`, `relationships`) | `dbt test --select stg_trips stg_zones` | |
16 | | - |
17 | | -## Folder structure |
18 | | - |
19 | | -```text |
20 | | -week-10/ |
21 | | - exercise_1/ |
22 | | - safe_divide.sql -- copy to macros/safe_divide.sql |
23 | | - stg_trips.sql -- copy to models/staging/stg_trips.sql |
24 | | - README.md |
25 | | - solutions/ |
26 | | - safe_divide.sql |
27 | | - stg_trips.sql |
28 | | - exercise_2/ |
29 | | - assert_fare_amount_non_negative.sql -- copy to tests/ |
30 | | - README.md |
31 | | - solutions/ |
32 | | - assert_fare_amount_non_negative.sql |
33 | | - exercise_3/ |
34 | | - fct_trips_broken.sql -- copy to models/marts/fct_trips.sql (overwrites) |
35 | | - README.md |
36 | | - solutions/ |
37 | | - fct_trips.sql |
38 | | - exercise_4/ |
39 | | - stg_trips.sql -- copy to models/staging/stg_trips.sql |
40 | | - fct_trips.sql -- copy to models/marts/fct_trips.sql |
41 | | - README.md |
42 | | - solutions/ |
43 | | - stg_trips.sql |
44 | | - fct_trips.sql |
45 | | - exercise_5/ |
46 | | - _stg_zones.yml -- copy to models/staging/_stg_zones.yml |
47 | | - _stg_trips.yml -- copy to models/staging/_stg_trips.yml |
48 | | - README.md |
49 | | - solutions/ |
50 | | - _stg_zones.yml |
51 | | - _stg_trips.yml |
| 9 | +```bash |
| 10 | +git clone https://github.com/lassebenni/nyc-taxi-dbt-reference.git nyc_taxi |
| 11 | +cd nyc_taxi |
| 12 | +cp profiles.yml.example profiles.yml # set your personal Week 9 login + schema |
| 13 | +git switch exercise-macros # then read EXERCISE.md |
52 | 14 | ``` |
53 | 15 |
|
54 | | -## How to run |
55 | | - |
56 | | -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. |
57 | | - |
58 | | -No `requirements.txt` is needed here: your dbt project already has `dbt-core` and `dbt-postgres` installed from Chapter 2. |
59 | | - |
60 | | -## Reference solutions and spoiler discipline |
| 16 | +| Exercise | Start branch | Solution branch | |
| 17 | +| --- | --- | --- | |
| 18 | +| Macros and computed columns (`safe_divide`) | [`exercise-macros`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-macros) | [`exercise-macros-solution`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-macros-solution) | |
| 19 | +| Write a singular test | [`exercise-singular-test`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-singular-test) | [`exercise-singular-test-solution`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-singular-test-solution) | |
| 20 | +| Debug a broken `ref()` | [`exercise-debug-ref`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-debug-ref) | [`exercise-debug-ref-solution`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-debug-ref-solution) | |
| 21 | +| Propagate a column change | [`exercise-column-propagation`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-column-propagation) | [`exercise-column-propagation-solution`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-column-propagation-solution) | |
| 22 | +| Add the four generic tests | [`exercise-generic-tests`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-generic-tests) | [`exercise-generic-tests-solution`](https://github.com/lassebenni/nyc-taxi-dbt-reference/tree/exercise-generic-tests-solution) | |
61 | 23 |
|
62 | | -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. |
| 24 | +Each branch is independent (all start from the complete project), so you can do them in any order. The full walkthrough for each is in the Week 10 Practice chapter of the Data Track curriculum. |
0 commit comments