Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dbt v1.6 to the course (#28) #46

Open
wants to merge 1 commit into
base: dbt-v15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion answers/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ models:
# Note, for incremental models this does not reset each run!
+hours_to_expiration: 168

marts:
# In reality this would only be useful if we had subfolders within marts/staging/intermediate
# but this is an illustration how you would apply a group to a folder
+group: sales

tests:
answers:
+severity: warn
+severity: warn
20 changes: 19 additions & 1 deletion answers/models/marts/dim_orders.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
version: 2

groups:
- name: sales
owner:
# 'name' or 'email' is required; additional properties allowed
email: [email protected]
slack: sales-data
github: sales-data-team

models:
- name: dim_orders
description: "Table of order level information"
# Set this model to be a part of the sales group we define above
# We don't need to define the group and the model in the same yml file!
config:
group: sales
# 3 settings:
# Private - only other models in the same (sales) group can ref() this model
# Protected - only other models in the same group or project can ref() this model
# Public - any other model can ref() this model
access: private

columns:

# Columns from stg_ecommerce__orders
Expand Down Expand Up @@ -95,4 +113,4 @@ models:
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_between:
min_value: 0
min_value: 0
25 changes: 25 additions & 0 deletions answers/models/staging/old_versions/stg_ecommerce__products_v1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
WITH source AS (
SELECT *

FROM {{ source('thelook_ecommerce', 'products') }}
)

SELECT
-- IDs
id AS product_id,

-- Other columns
cost,
retail_price,
department

{#- Unused columns:
- distribution_center_id
- inventory_item_id
- category
- brand
- sku
- name
#}

FROM source
13 changes: 13 additions & 0 deletions answers/models/staging/stg_ecommerce__order_items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,46 @@ version: 2
models:
- name: stg_ecommerce__order_items
description: "Line items from orders"
config:
contract:
enforced: true
columns:
- name: order_item_id
# Model tests (run AFTER model is built)
tests:
- not_null:
severity: error
- unique:
severity: error
# Model contract (run BEFORE model is built)
data_type: INTEGER
constraints:
# Note - we could get rid of the not_null check above as it basically duplicates the contract
- type: not_null

- name: order_id
data_type: INTEGER
tests:
- not_null
- relationships:
to: ref('stg_ecommerce__orders')
field: order_id

- name: user_id
data_type: INTEGER
tests:
- not_null

- name: product_id
data_type: INTEGER
tests:
- not_null
- relationships:
to: ref('stg_ecommerce__products')
field: product_id

- name: item_sale_price
data_type: FLOAT64
description: "How much the item sold for"
tests:
- not_null
Expand Down
6 changes: 3 additions & 3 deletions answers/models/staging/stg_ecommerce__products.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ SELECT
-- Other columns
cost,
retail_price,
department
department,
brand -- new column added in v2

{#- Unused columns:
- distribution_center_id
- inventory_item_id
- distribution_center_id
- category
- brand
- sku
- name
#}
Expand Down
26 changes: 26 additions & 0 deletions answers/models/staging/stg_ecommerce__products.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,29 @@ models:
# quote defaults to true, but this just shows how you could set it to
# false if you wanted to have non-string values (e.g. numbers or a TRUE/FALSE column)
quote: true

- name: brand
description: "Brand of the product"

# If you don't specify the latest, version, dbt will either look
# for the unversioned file name (e.g. stg_ecommerce__products.sql), or reference the
# latest version. In this case, it'd reference version 2 automatically, but this shows you
# how you could do a pre-release version (e.g. create version 2, but by default dbt points at version 1)
# using latest_version: 1
latest_version: 2
versions:
# Matches what's above -- nothing more needed
- v: 1
columns:
# This means: use the 'columns' list from above, but exclude "brand" as we added it in v2
- include: all
exclude: [brand]

# We added a new brand column
- v: 2
# Makes this table stay as stg_ecommerce__products in our database!
config:
alias: stg_ecommerce__products
columns:
# This means: use the 'columns' list from above
- include: all
13 changes: 1 addition & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
dbt-bigquery==1.4.1
google-api-core==2.8.2
google-auth==2.9.0
google-auth-oauthlib==0.5.2
google-cloud-bigquery==3.5.0
google-cloud-bigquery-storage==2.14.2
google-cloud-core==2.3.1
google-cloud-dataproc==5.0.3
google-cloud-storage==2.5.0
google-crc32c==1.3.0
google-resumable-media==2.3.3
googleapis-common-protos==1.56.4
dbt-bigquery==1.6.1