Keep the dbt project behind an RW’s morning larvae report: ref, tests, incremental, snapshots. 14 levels, played right in the browser with nothing to install.
dbt turns raw data in a warehouse into tables ready to read. Each model is one .sql file holding one SELECT. dbt wraps it into a table or a view named after the file. dbt build builds every model and runs its tests. dbt works out the order itself from the arrows between models, and those arrows come from the ref() in each model's code. The lineage board on the post's wall draws those arrows. The laptop's screen shows dbt's log as it is.
A source is a table loaded into the warehouse by something outside dbt. At the post, that is the 22:00 pull from SiJentik. A source is registered in YAML with its name and schema, and models read it with source(). That way dbt knows which table every number comes from: the data's lineage. A staging model usually sits on one source table each. Its job is to tidy the columns and drop rows that are not data.
Grain is what one row of a table means. The post's fact table of checks: one row is one card, one house checked on one day. Finer data, one row per container, must be summed up to that grain before the join. Otherwise one card appears many times, and every count(*) counts containers as houses. The ABJ is worked out per house: larva-free houses divided by houses checked, times 100.
A dbt test is written in YAML beside its model. Each test becomes one SELECT that looks for rows breaking the rule. The test passes when that finds 0 rows. There are four built-in tests: unique (no value twice), not_null (nothing empty), accepted_values (values from a given list) and relationships (every value exists in a column of another table). dbt build runs a test right after its model. When a test fails, the models downstream of it are skipped.
dbt has three ways to run a project. dbt run only builds models. dbt test only runs tests on tables that already exist. dbt build does both in turn along the arrows: a model, its tests, then the next model. Every test has a severity. error makes the build skip the models downstream. warn records a warning and lets the build go on.
A daily report is usually worked out with group by date. The trouble is that a day without data makes no row at all, and the chart skips it without a mark. A spine is a table holding every date, and every neighbourhood, that should be there. The data is joined to the spine with left join, so an empty day still appears and can be tested.