Skip to content

Fix issues identified by DBT assistant #42

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

Open
wants to merge 5 commits into
base: main
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
10 changes: 4 additions & 6 deletions jaffle_shop/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
Expand All @@ -22,14 +21,13 @@ clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_packages"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/
# directory as views. These settings can be overridden in the individual model
# In this example config, we tell dbt to build all models in the jaffle_shop/
# directory as tables. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
jaffle_shop:
# Config indicated by + and applies to all files under models/example/
+materialized: table
# Config indicated by + and applies to all files under models/jaffle_shop/
+materialized: table
14 changes: 0 additions & 14 deletions jaffle_shop/models/customers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,32 @@
}}

with customers as (

select * from {{ ref('stg_customers') }}

),

orders as (

select * from {{ ref('stg_orders') }}

),

customer_orders as (

select
customer_id,

min(order_date) as first_order_date,
max(order_date) as most_recent_order_date,
count(order_id) as number_of_orders

from orders

group by 1

),

final as (

select
customers.customer_id,
customers.first_name,
-- customers.last_name,
customer_orders.first_order_date,
customer_orders.most_recent_order_date,
coalesce(customer_orders.number_of_orders, 0) as number_of_orders

from customers

left join customer_orders using (customer_id)

)

select * from final
21 changes: 12 additions & 9 deletions jaffle_shop/models/schema.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: 2

models:
- name: customers
description: One record per customer
Expand All @@ -17,20 +18,21 @@ models:
dimension:
type: date
- name: first_name
description: ""
description: Customer's first name
meta:
dimension:
type: string
- name: most_recent_order_date
description: ""
description: Date of the customer's most recent order
meta:
dimension:
type: date
- name: number_of_orders
description: ""
description: Total number of orders placed by the customer
meta:
dimension:
type: number

- name: stg_customers
description: This model cleans up customer data
columns:
Expand All @@ -43,15 +45,16 @@ models:
dimension:
type: number
- name: first_name
description: ""
description: Customer's first name
meta:
dimension:
type: string
- name: last_name
description: ""
description: Customer's last name
meta:
dimension:
type: string

- name: stg_orders
description: This model cleans up order data
columns:
Expand All @@ -64,6 +67,7 @@ models:
dimension:
type: number
- name: status
description: Current status of the order
tests:
- accepted_values:
values:
Expand All @@ -72,25 +76,24 @@ models:
- completed
- return_pending
- returned
description: ""
meta:
dimension:
type: string
metrics:
total_order_count:
type: count
- name: customer_id
description: Foreign key to stg_customers
tests:
- not_null
- relationships:
to: ref('stg_customers')
field: customer_id
description: ""
meta:
dimension:
type: number
- name: order_date
description: ""
description: Date when the order was placed
meta:
dimension:
type: date
type: date
17 changes: 12 additions & 5 deletions jaffle_shop/models/staging/stg_customers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
)
}}

select
id as customer_id,
first_name,
last_name
with source as (
select * from {{ source('jaffle_shop', 'customers') }}
),

from `dbt-tutorial`.jaffle_shop.customers
renamed as (
select
id as customer_id,
first_name,
last_name
from source
)

select * from renamed
19 changes: 13 additions & 6 deletions jaffle_shop/models/staging/stg_orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
)
}}

select
id as order_id,
user_id as customer_id,
order_date,
status
with source as (
select * from {{ source('jaffle_shop', 'orders') }}
),

from `dbt-tutorial`.jaffle_shop.orders
renamed as (
select
id as order_id,
user_id as customer_id,
order_date,
status
from source
)

select * from renamed