Skip to content
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
11 changes: 6 additions & 5 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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
name: 'my_new_project'
name: 'jaffle_shop'
version: '1.0.0'
config-version: 2

Expand Down Expand Up @@ -32,7 +32,8 @@ clean-targets: # directories to be removed by `dbt clean`
# as tables. These settings can be overridden in the individual model files
# using the `{{ config(...) }}` macro.
models:
my_new_project:
# Applies to all files under models/example/
example:
materialized: view
staging:
jaffle_shop:
+materialized: view
marts:
+materialized: view
26 changes: 26 additions & 0 deletions macros/test_had_duplicates.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% macro test_has_duplicates(model, column_name) %}

with validation as (

select
{{ column_name }} as even_field

from {{ model }}

),

validation_errors as (

select
even_field

from validation
-- if this is true, then even_field is actually odd!
where (even_field % 2) = 1

)

select count(*)
from validation_errors

{% endmacro %}
27 changes: 0 additions & 27 deletions models/example/my_first_dbt_model.sql

This file was deleted.

6 changes: 0 additions & 6 deletions models/example/my_second_dbt_model.sql

This file was deleted.

21 changes: 0 additions & 21 deletions models/example/schema.yml

This file was deleted.

29 changes: 29 additions & 0 deletions models/marts/core/dim_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
with customers as (
select * from {{ ref('stg_customers')}}
),
orders as (
select * from {{ ref('fct_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,
sum(amount) as lifetime_value
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,
customer_orders.lifetime_value
from customers
left join customer_orders using (customer_id)
)
select * from final
30 changes: 30 additions & 0 deletions models/marts/core/fct_orders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
with orders as (
select * from {{ ref('stg_orders' )}}
),

payments as (
select * from {{ ref('stg_payments') }}
),

order_payments as (
select
order_id,
sum(case when status = 'success' then amount end) as amount

from payments
group by 1
),

final as (

select
orders.order_id,
orders.customer_id,
orders.order_date,
coalesce(order_payments.amount, 0) as amount

from orders
left join order_payments using (order_id)
)

select * from final
6 changes: 6 additions & 0 deletions models/staging/jaffle_shop/stg_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
id as customer_id,
first_name,
last_name

from raw.jaffle_shop.customers
20 changes: 20 additions & 0 deletions models/staging/jaffle_shop/stg_jaffle_shop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

models:
- name: stg_customers
columns:
- name: customer_id
tests:
- unique
- not_null
- name: stg_orders
columns:
- name: status
tests:
- accepted_values:
values:
- completed
- shipped
- returned
- placed
- return_pending
6 changes: 6 additions & 0 deletions models/staging/jaffle_shop/stg_orders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
id as order_id,
user_id as customer_id,
order_date,
status
from raw.jaffle_shop.orders
11 changes: 11 additions & 0 deletions models/staging/stripe/stg_payments.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
select
id as payment_id,
orderid as order_id,
paymentmethod as payment_method,
status,

-- amount is stored in cents, convert it to dollars
amount / 100 as amount,
created as created_at

from raw.stripe.payment
Empty file added tests/schema.yml
Empty file.