What is a dbt model?

Introduction to dbt

Mike Metzger

Data Engineer

What is a data model?

  • Conceptual, with different definitions depending on context
  • Represents the logical meaning of data
  • How the data and its components relate
  • Helps users collaborate
Introduction to dbt

What is a data model?

  • Conceptual, with different definitions depending on context
  • Represents the logical meaning of data
  • How the data and its components relate
  • Helps users collaborate
Species # of legs Venomous
Cheetah 4 No
Duck 2 No
Platypus 4 Yes
Rattlesnake 0 Yes
Introduction to dbt

What is a model in dbt?

  • Represents the various transformations
  • Typically written in SQL
    • Newer versions can use Python
  • Usually a SELECT query
  • Each model represented by a text file with .sql extension
Introduction to dbt

Simple dbt model

  1. Create a directory in the models directory
  2. Create a .sql file in above directory
  3. Add the SQL statement to the newly created file
  4. Run dbt run to materialize the model
bash> mkdir models/order
bash> touch models/order/customer_orders.sql
select first_name, 
       last_name,
       shipping_address,
       item_quantity
from source_table

bash> dbt run

Introduction to dbt

Reading from Parquet

  • Parquet?
    • Columnar binary file format
    • DuckDB can read Parquet files directly
    • read_parquet
      • SELECT * FROM read_parquet('filename.parquet')
    • Or simply the filename in single quotes
      • SELECT * FROM 'filename.parquet'
Introduction to dbt

Let's practice!

Introduction to dbt

Preparing Video For Download...