diff --git a/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql b/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql index a3d2c59dc..6a5ed966d 100644 --- a/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql +++ b/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql @@ -1,7 +1,7 @@ {% 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 @@ -10,9 +10,7 @@ select , SUM(payments.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 \ No newline at end of file +GROUP BY orders.customer_id \ No newline at end of file diff --git a/jaffle_shop/models/staging/src_seed/_models.yml b/jaffle_shop/models/staging/src_seed/_models.yml index 46abf1529..ba35bcf76 100644 --- a/jaffle_shop/models/staging/src_seed/_models.yml +++ b/jaffle_shop/models/staging/src_seed/_models.yml @@ -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 @@ -14,7 +16,9 @@ models: - name: stg_payments columns: + description: staging layer for all payments with a FK to order - name: payment_id + description: Primary Key tests: - unique - not_null @@ -22,3 +26,12 @@ models: 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 \ No newline at end of file diff --git a/jaffle_shop/models/staging/src_seed/sensitive/_models.yml b/jaffle_shop/models/staging/src_seed/sensitive/_models.yml index 6649bf8af..e75f52c6c 100644 --- a/jaffle_shop/models/staging/src_seed/sensitive/_models.yml +++ b/jaffle_shop/models/staging/src_seed/sensitive/_models.yml @@ -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