Data Engineering · Module 15
Transformations with dbt
- Lessons
- 12
- Free
- 1
- Reading
- ~3 h
Your progress
0 / 12 lessons done
Sign in to trackLessons
- dbt: transformations as version-controlled codeFreeMost data teams that load raw data into a warehouse build their reporting tables with SQL. dbt is the common way to keep that SQL in git, run it in the right order and test it before anyone reads the numbers.
- dbt models, sources and referencesEvery dbt project is a graph that dbt draws from ref() and source() calls. Get the calls right and dbt builds in the right order, in the right schema; skip one and a model can quietly read yesterday’s data.
- Materializations: views, tables and incremental modelsThe same SELECT can cost seconds or an hour a night, and a dashboard can open in a second or in minutes, depending on one config line. Choosing it per model is most of what keeps a dbt build inside its window.
- Testing data with dbtA dbt project is only as trustworthy as the tests that run between its models. Choosing what to test, where in the graph, and how loudly a failure should stop the night decides whether a wrong number reaches finance or a harmless oddity wakes someone at 03:00.
- dbt contracts, versions and microbatch modelsOnce other teams read your models, a column rename is an outage for them, and a billion-row event table can’t be rebuilt every time a night goes wrong. Contracts, versions and microbatch models are dbt’s tools for both.
- Documentation and lineage in dbtEvery model you change has readers you didn’t write. Documentation and lineage are how you find them before a rename breaks a finance report or a forecast, not after.
- Incremental models and late-arriving dataAn incremental model trusts its filter. If the filter skips a late row, no test fails and no error appears; the number is wrong, every night, until someone rebuilds the table.
- dbt snapshots for slowly changing dataEvery other dbt model can be rebuilt from its inputs, but the source only holds today’s values. A snapshot is the one table that remembers, so a wrong setting writes wrong history that no rerun can repair.
- Macros and packages in dbtEvery dbt project of any size repeats a few business rules across many models. Macros keep those rules identical everywhere, and packages let a team reuse tested ones, but both can also hide SQL from the people who review it.
- Structuring a dbt project and running it in CIOnce more than one person changes a dbt project, every pull request needs a build you can trust before merge. Done badly, that build takes an hour or writes over production; done well, it takes minutes and touches nothing shared.
- Case: Monzo’s 12,000 dbt models across 100 teamsOnce more than one team writes dbt models, a change in one team’s model can break another’s, and every team’s habits add to the warehouse bill. Monzo’s account shows one way to keep many teams in charge of their own models without letting the project drift.
- Design: a dbt project for sales reportingMost analytics teams end up with one dbt project that feeds the reports the business runs on. Each feature can be set up correctly and the report still be late or wrong, so the project has to be designed as a whole, backwards from the people who read it.
Practise with
No tools or paper guides for this module yet.
Terms this module teaches 54
Open glossaryAdapter dispatch
A dbt mechanism that picks a macro's implementation by the warehouse in use, looking for a version prefixed with the adapter's name, then one prefixed default__.
column-level lineage
Lineage that records which source columns each output column is computed from, not only which tables feed which.
Cross-team interface (data model)
A model a team declares as safe for other teams to build on, kept documented, tested and stable, so changes to the team’s other models can’t break them.
Custom schema (dbt)
A schema a dbt model asks for in its config, which generate_schema_name combines with the target's schema to choose where the model is built.
dbt
A tool that turns SQL select statements into tables and views in a warehouse, runs them in dependency order, and tests the results.
dbt adapter
The part of dbt that knows how to connect to one data platform and write SQL in its dialect.
dbt clone
A dbt command that copies selected models from another environment’s state into the target schema, as zero-copy clones where the warehouse supports them, or as views pointing at the originals.
dbt model
One SQL select statement in its own file, which dbt turns into a table or view in the warehouse.
dbt package
A dbt project that another project installs with dbt deps to reuse its macros, tests and models.
dbt project
A folder with a dbt_project.yml file at its root that holds a team’s models, tests, seeds, snapshots and macros.
dbt seed
A small CSV file in a dbt project that dbt loads into the warehouse as a table.
dbt source
A table that dbt reads but doesn’t build, declared in a YAML file and read with source() so it appears in the dependency graph.
dbt target
A named connection in dbt’s profile, such as dev or prod, that sets which warehouse and schema a run builds in.
Defer (dbt)
A dbt option that makes a ref() to a model that isn’t selected and doesn’t exist in the target schema point at that model in another environment’s manifest instead.
docs block
A named piece of Markdown in a dbt project that any model or column description can reuse with doc().
Dynamic table (Snowflake)
A Snowflake table defined by a query that Snowflake refreshes by itself to stay within a set staleness, its target lag.
Ephemeral model
A dbt model that is never built in the warehouse; its SQL is pasted into each model that uses it as a common table expression.
exposure (dbt)
A declaration in a dbt project of something outside dbt that reads its models, such as a dashboard, notebook or ML job, with an owner and the models it depends on.
full refresh
A dbt run with the --full-refresh flag, which drops an incremental model’s table and rebuilds it from all of history.
Generic data test
A dbt data test written once with blanks for the table and column, then applied to any column with one line of YAML.
GitHub Actions
GitHub’s built-in automation service, which runs workflows defined in YAML files in the repository when events such as a pull request happen.
graph operator
A symbol in a dbt selector that extends a selection through the DAG: a plus after a name adds everything downstream, a plus before it adds everything upstream.
Group (dbt)
A named set of dbt models with one owner; private models can be referenced only from inside their group.
Incremental model
A dbt model built as a table once, then updated each run with only the rows its filter selects.
incremental strategy
The setting that decides how an incremental dbt model writes new rows into its table: append, merge, delete+insert, insert_overwrite or microbatch.
Indirect selection
dbt’s rule for which tests run when you select only some models: eager runs a test if any of its models is selected, cautious only if all of them are.
Intermediate model
A dbt model between staging and marts that holds a join or step more than one mart needs, and that reports don’t read directly.
Jinja
A text template language; dbt uses it to fill in table names and reusable pieces of SQL before running a model.
Latest version pointer
In dbt v2, a view named after a versioned model that points at whichever version is marked latest, so readers who query the plain name follow it.
Lookback (microbatch)
How many batches before the current one a microbatch model rebuilds on each run, to pick up rows that arrive late.
Macro (dbt)
A named piece of Jinja in a dbt project that outputs SQL text, or returns a value, wherever a model calls it.
manifest.json
The file dbt writes to target/ describing the whole project: every model, test, source and exposure, and the edges between them.
Materialization (dbt)
The kind of object dbt builds from a model, such as a view, a table or an incremental table, which decides when the model’s SQL runs.
Microbatch model
A dbt incremental model that splits time into batches by an event-time column and builds each batch with its own query, so any range can be rebuilt or retried batch by batch.
Model access (dbt)
A dbt model setting that decides which other models may ref it: private (same group), protected (same project) or public (anyone).
Model contract (dbt)
A dbt model setting that lists every column’s name and data type; when enforced, dbt checks the model’s query against it before building and fails the build on a mismatch.
Model generator
A tool that writes data models from a short description, such as an object’s key, source events and fields, so every team’s base models are built the same way.
Model version (dbt)
One of several shapes of the same dbt model, each built from its own SQL file into its own table, so readers can move from an old shape to a new one on their own schedule.
nondeterministic merge
A MERGE where one target row matches several source rows, so the result depends on which match is applied; Snowflake stops it with an error.
on_schema_change
A dbt setting that decides what an incremental model does when its SELECT returns different columns from its existing table: ignore, fail, append new columns or sync all columns.
Pull request
A proposed change to a code repository, shown as a diff that others review and automated checks run on before it is merged.
ref()
The dbt function a model uses to read another model; it compiles to that model’s table name and adds an edge to dbt’s dependency graph.
Singular data test
A dbt data test written as one SQL file in the tests folder, returning the rows that break a rule.
snapshot (dbt)
A table dbt changes on every run but never rebuilds: each run compares a source with its current rows by key, closes the rows that changed and inserts new versions, so it keeps type 2 history the source has overwritten.
snapshot strategy
How a dbt snapshot decides a row changed: the timestamp strategy compares an updated_at column, the check strategy compares a list of columns.
Staging model
A dbt model that reads one raw source table, renames and cleans its columns, and is the only model allowed to read that source.
state selection
Selecting dbt nodes by comparing the project with a manifest from an earlier run, such as only the models that changed.
static analysis (dbt)
dbt v2’s check of each model’s SQL before it runs: it builds a logical plan, finds type errors and, in strict mode, traces column-level lineage.
Store failures
A dbt setting that saves a test’s failing rows to a table in the warehouse so people can query them.
Test severity
The setting that decides whether a failing data test stops a run with an error or only warns, often with row-count thresholds.
Transient table
A Snowflake table with at most 1 day of Time Travel and no fail-safe period; dbt creates its tables this way by default.
unique_key
The column or list of columns an incremental dbt model uses to match new rows with rows already in its table; it should name one row each.
Version control
A system, such as git, that records every change to a set of files, who made it and why, so changes can be reviewed and undone.
Zero-copy clone
A copy of a table that starts by sharing the original’s stored data, so it is made almost instantly and costs extra storage only for rows that later change.