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

Elliot cert #10

Open
wants to merge 4 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
12 changes: 12 additions & 0 deletions jaffle_shop/models/final/finance/_exposures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

exposures:
- name: customer_return_total
description: Inksacio App to show the total sum of customer returns, per customer (for both completed and upcoming)
type: dashboard
url: https://inksacio.eks.octojaffle.engineering/customer_return_totals/
owner:
name: 'Elliot Taylor'
email: [email protected]
depends_on:
- ref('fnl_finance_customerreturnstotal')
13 changes: 13 additions & 0 deletions jaffle_shop/models/final/finance/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2

models:
- name: fnl_finance_customerreturnstotal
description: >
This table gives one row per customer, with the total of their completed returns,
pending_returns and the sum of the 2
columns:
- name: customer_id
description: primary key
tests:
- unique
- not_null
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% set return_states = ['returned', 'return_pending'] %}

select
orders.customer_id

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

, SUM(orders.amount_dollars) AS sum_return_amount_dollars

from {{ ref('wh_orders') }} AS orders
where orders.status IN ('returned', 'return_pending')
GROUP BY orders.customer_id
12 changes: 12 additions & 0 deletions jaffle_shop/models/final/sales/_exposures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

exposures:
- name: new_customer_history
description: Inksacio App to show monthly new customer history
type: dashboard
url: https://inksacio.eks.octojaffle.engineering/new_customer_history/
owner:
name: 'Elliot Taylor'
email: [email protected]
depends_on:
- ref('fnl_sales_newcustomerhistory')
13 changes: 13 additions & 0 deletions jaffle_shop/models/final/sales/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2

models:
- name: fnl_sales_newcustomerhistory
description: >
This table gives one row per truncated month with the count
of customers that have created their first order within this month
columns:
- name: first_order_month
description: primary key
tests:
- unique
- not_null
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select
date_trunc('month', first_order) AS first_order_month
, count(*) AS number_customers
from {{ ref('wh_customers') }}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
version: 2

models:
- name: stg_customers
columns:
- name: customer_id
tests:
- unique
- not_null

- name: stg_orders
description: staging layer for all orders
columns:
- name: order_id
description: Primary Key
tests:
- unique
- not_null
Expand All @@ -20,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
18 changes: 18 additions & 0 deletions jaffle_shop/models/staging/src_seed/sensitive/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
- name: first_name
meta:
sensitive: true
- name: last_name
meta:
sensitive: true
3 changes: 3 additions & 0 deletions jaffle_shop/models/staging/src_seed/stg_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT
{{ hash_sensitive_columns('stg_customers_pii') }}
FROM {{ ref('stg_customers_pii') }}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ renamed as (
payment_method,

-- `amount` is currently stored in cents, so we convert it to dollars
amount / 100 as amount
amount / 100 as amount_dollars

from source

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2

models:
- name: customers
- name: wh_customers
description: This table has basic information about a customer, as well as some derived facts based on a customer's orders

columns:
Expand Down Expand Up @@ -29,7 +29,7 @@ models:
- name: total_order_amount
description: Total value (AUD) of a customer's orders

- name: orders
- name: wh_orders
description: This table has basic information about orders, as well as some derived facts based on payments

columns:
Expand All @@ -44,7 +44,7 @@ models:
tests:
- not_null
- relationships:
to: ref('customers')
to: ref('wh_customers')
field: customer_id

- name: order_date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ final as (
customers.customer_id,
customers.first_name,
customers.last_name,

customer_orders.first_order,
customer_orders.most_recent_order,
customer_orders.number_of_orders,
Expand Down
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
2 changes: 2 additions & 0 deletions jaffle_shop/seeds/dbt_project_evaluator_exceptions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fct_name,column_name,id_to_exclude,comment
fct_staging_dependent_on_staging,parent,stg_customers_pii,Scrubbing pii permitted in staging layer.