Giter VIP home page Giter VIP logo

dbt-dummy's Introduction

dbt-dummy

This is a dummy dbt (data build tool) project you can use to populate dbt seeds, models, snapshots and tests for testing purposes or experimentation.

The docker-compose.yml file consists of two services:

  • postgres
  • dbt

that are used to build the data models defined in the example project into a target Postgres database.

postgres service and the Sakila Database

This is an instance of a Postgres database initialised with Sakila database (and thus we are using the frantiseks/postgres-sakila image which is available on Docker Hub).

The database models a DVD rental store and contains several normalised tables that correspond to films, payments, customers and other entities.

Sakila Database was developed by Mike Hillyer, who used to be a member of the AB documentation team at MySQL. For more information regarding Sakila Database you can refer to the official MySQL documentation.

dbt service

This service is built out of the Dockerfile and is responsible for creating dbt seeds, models and snapshots on postgres service. The example dbt project contains seeds, models (staging, intermediate and mart) as well as snapshots.

Note that this is a dummy project, meaning that some entities (including aggregations) might not make too much sense from a business perspective. For example, even though the Sakila database contains the customer table already, we construct another table called customer_base that corresponds to a dbt seed, and is loaded form an external csv file.

Additionally, the models created may not be the perfect examples of what it should be considered as an intermediate or mart model. In general if you are interested in gaining a deeper understanding of these terms I would encourage you to read the following articles:

Feel free to add, modify or remove models while cloning or forking the project in order to serve the purpose you intend to use it for.

Running the dummy dbt project

First, let's build the services defined in our docker-compose.yml file:

docker-compose build

and now let's run the services so that the dbt models are created in our target Postgres database:

docker-compose up

This will spin up two containers namely dbt (out of the dbt-dummy image) and postgres (out of the frantiseks/postgres-sakila image).

Notes:

  • For development purposes, both containers will remain up and running
  • If you would like to end the dbt container, feel free to remove the && sleep infinity in CMD command of the Dockerfile

Building additional or modified data models

Once the containers are up and running, you can still make any modifications in the existing dbt project and re-run any command to serve the purpose of the modifications.

In order to build your data models, you first need to access the container.

To do so, we infer the container id for dbt running container:

docker ps

Then enter the running container:

docker exec -it <container-id> /bin/bash

And finally:

# Install dbt deps
dbt deps

# Build seeds
dbt seeds --profiles-dir profiles

# Build data models
dbt run --profiles-dir profiles

# Build snapshots
dbt snapshot --profiles-dir profiles

# Run tests
dbt test --profiles-dir profiles

Alternatively, you can run everything in just a single command:

dbt build --profiles-dir profiles

Querying seeds, models and snapshots on Postgres

In order to query and verify the seeds, models and snapshots created in the dummy dbt project, simply follow the steps below.

Find the container id of the postgres service (postgres):

docker ps 

Then run

docker exec -t <container-id> /bin/bash

We will then use psql, a terminal-based interface for PostgreSQL that allows us to query the database:

psql -U postgres

Now you can query the tables constructed form the seeds, models and snapshots defined in the dbt project:

-- Query seed tables
SELECT * FROM customer_base;

-- Query staging views
SELECT * FROM stg_payment;

-- Query intermediate views
SELECT * FROM int_customers_per_store;
SELECT * FROM int_revenue_by_date;

-- Query mart tables
SELECT * FROM cumulative_revenue;

-- Query snapshot tables
SELECT * FROM int_stock_balances_daily_grouped_by_day_snapshot;

dbt-dummy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dbt-dummy's Issues

Enable DBT Docs to be served

For the "full dbt experience" I'd consider it relevant to offer serving DBT docs for the project. Also, would help development.

I created a PR which addresses this, but perhaps you want to implement your own way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.