Skip to content

Commit

Permalink
Lineage Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliotTaylor23 committed Jan 4, 2023
1 parent 74d472b commit 3511e9c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{% set return_states = ['returned', 'return_pending'] %}

select
custs.customer_id
orders.customer_id

{% for return_state in return_states -%}
, SUM(payments.amount_dollars) FILTER (WHERE orders.status =' {{ return_state }}') AS {{ return_state }}_amount_dollars
, SUM(orders.amount_dollars) FILTER (WHERE orders.status =' {{ return_state }}') AS {{ return_state }}_amount_dollars
{% endfor -%}

, SUM(payments.amount_dollars) AS sum_return_amount_dollars
, SUM(orders.amount_dollars) AS sum_return_amount_dollars

from {{ ref('wh_orders') }} AS orders
left join {{ ref('wh_customers') }} AS custs
on custs.customer_id = orders.customer_id
left join {{ ref('stg_payments') }} AS payments
on payments.order_id = orders.order_id
where orders.status IN ('returned', 'return_pending')
GROUP BY customer_id
GROUP BY orders.customer_id
13 changes: 13 additions & 0 deletions jaffle_shop/models/staging/src_seed/_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ version: 2

models:
- name: stg_orders
description: staging layer for all orders
columns:
- name: order_id
description: Primary Key
tests:
- unique
- not_null
Expand All @@ -13,12 +15,23 @@ models:
values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']

- name: stg_payments
description: staging layer for all payments with a FK to order
columns:
- name: payment_id
description: Primary Key
tests:
- unique
- not_null
- name: payment_method
tests:
- accepted_values:
values: ['credit_card', 'coupon', 'bank_transfer', 'gift_card']

- name: stg_customers
description: staging layer for all customers, PII hashed
columns:
- name: customer_id
description: Primary Key
tests:
- unique
- not_null
3 changes: 3 additions & 0 deletions jaffle_shop/models/staging/src_seed/sensitive/_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ version: 2

models:
- name: stg_customers_pii
description: >
Table that includes all info about all customers, with PII hashed
columns:
- name: customer_id
description: Primary Key
tests:
- unique
- not_null
Expand Down
2 changes: 1 addition & 1 deletion jaffle_shop/models/warehouse/wh_orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final as (

{% endfor -%}

order_payments.total_amount as amount
order_payments.total_amount as amount_dollars

from orders

Expand Down

0 comments on commit 3511e9c

Please sign in to comment.