Sitemap

dbt Guide

3 min readJun 27, 2023

--

Talk is cheap, show me the code

What is dbt?

dbt(data build guide) is an open-source project for managing data transformation in a data warehouse. Once data is loaded into a warehouse, dbt enables the teams to manage all data transformations require for driving analytics.

It also comes with built in testing and documentation so we can have a high level of confidence in the tables we’re generating and analyzing.

Running dbt

If you’re interested in using dbt, the dbt documentation has a great tutorial on getting setup to work on data from a fictional business called Jaffle Shop.

Get Lymah’s stories in your inbox

Join Medium for free to get updates from this writer.

If you wish to use dbt and contribute to the data team project, you’ll need to gain access to our Snowflake instance, which can be done via an access request.

Configuration

  • Ensure you have access to our Snowflake instance
  • Ensure you have Make installed (should be installed on new Macs and with XCode)
  • Create a folder in your home directory called .dbt
  • In the ~/.dbt/ folder there should be a profiles.ymlfile that looks like this sample profile
  • The smallest possible warehouse should be stored as an environment variable. Our dbt jobs use SNOWFLAKE_TRANSFORM_WAREHOUSE as the variable name to identify the warehouse. The environment variable can be set in the .bashrc or .zshrc file as follows:
  • export SNOWFLAKE_TRANSFORM_WAREHOUSE="ANALYST_XS"
  • In cases where more compute is required, this variable can be overwritten at run. We will cover how to do this in the next section.
  • Clone the analytics project
  • If running on Linux:
  • Ensure you have Docker installed

Note that many of these steps are done in the onboarding script we recommend new analysts run.

Choosing the right Snowflake warehouse when running dbt

Our Snowflake instance contains warehouses of multiple sizes, which allow for dbt developers to allocate differing levels of compute resources to the queries they run. The larger a warehouse is and the longer it runs, the more the query costs. For example, it costs 8 times more to run a Large warehouse for an hour than it costs to run an X-Small warehouse for an hour.

If you have access to multiple warehouses, you can create an entry for each warehouse in your profiles.yml file. Having done this, you will be able to specify which warehouse should run when you call dbt run

Example

Imagine that you are a Data Team member who needs to make a change to a dbt model. You have access to both an X-Small warehouse and a Large warehouse, and your profiles.yml file is set up like so:

Press enter or click to view image in full size
Example of code snippet

You open up your terminal and code editor, create a new branch, make an adjustment to a dbt model, and save your changes. You are ready to run dbt locally to test your changes, so you enter in the following command: dbt run --models @{model_name}. dbt starts building the models, and by default it builds them using the ANALYST_XS warehouse. After a while, the build fails due to a timeout error. Apparently the model tree you are building includes some large or complex models. In order for the queries to complete, you'll need to use a larger warehouse. You want to retry the build, but this time you want dbt to use the ANALYST_L warehouse instead of ANALYST_XS. So you enter in dbt run --models @{model_name} --target dev_l, which tells dbt to use the warehouse you specified in the dev_l target in your profiles.yml file. After a few minutes, the build completes and you start checking your work

--

--

Lymah
Lymah

Written by Lymah

Software Engieneer || Technical Writer || Open Source Contributor ||