- Defined the schema of the source tables.
- Created a staging layer to clean and rename the columns.
- Created snapshots of the staging tables to track changes over time.
Our dimension tables follow the following naming convention:
dim_<entity_name>for simple dimensions.dim_<entity_name>_historyfor slowly changing dimensions.
You can find all the code for creating these dimension tables in the
models/core/dimensions/ directory
of the example-dbt-project.Creating Dimension Tables
dim_users_history
Specification
We would like ourdim_users_history table to have the following columns.
Note that our user_id is no longer a primary key in this table.
This is because since we can now have multiple rows for each user, each row representing a different version of the user’s history,
the user_id is no longer unique.
Instead, we have a dbt_scd_id column that acts as the primary key.
We have also added a column called is_current that indicates whether a row is the current version of the user.
Model
The following dbt model creates a slowly changing dimension table for theusers table.
dim_merchants_history
Specification
We would like ourdim_merchants_history table to have the following columns:
Model
The following dbt model creates a slowly changing dimension table for themerchants table.
dim_items_history
Specification
We would like ourdim_items_history table to have the following columns:
Model
The following dbt model creates a slowly changing dimension table for theitems table.
dim_promotions_history
Specification
We would like ourdim_promotions_history table to have the following columns:
The following dbt model creates a slowly changing dimension table for the
promotions table.