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

changes for new configs #11

Open
wants to merge 2 commits into
base: elliot-cert
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: 0 additions & 12 deletions jaffle_shop/models/final/finance/_exposures.yml

This file was deleted.

14 changes: 14 additions & 0 deletions jaffle_shop/models/final/finance/_models.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
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: elliot.taylor@octojaffle.com
depends_on:
- ref('fnl_finance_customerreturnstotal')

models:
- name: fnl_finance_customerreturnstotal
meta:
owner: 'matthew.elsham@octoenergy.com'
team_owner: '!subteam^S7K9CR63D' #@datateam
description: >
This table gives one row per customer, with the total of their completed returns,
pending_returns and the sum of the 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set return_states = ['returned', 'return_pending'] %}

select
SELECT
orders.customer_id

{% for return_state in return_states -%}
Expand All @@ -9,6 +9,6 @@ select

, 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
FROM {{ ref('wh_orders') }} AS orders
WHERE orders.status IN ('returned', 'return_pending')
GROUP BY orders.customer_id
12 changes: 0 additions & 12 deletions jaffle_shop/models/final/sales/_exposures.yml

This file was deleted.

16 changes: 15 additions & 1 deletion jaffle_shop/models/final/sales/_models.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
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: elliot.taylor@octojaffle.com
depends_on:
- ref('fnl_sales_newcustomerhistory')

models:
- name: fnl_sales_newcustomerhistory
meta:
owner: 'matthew.elsham@octoenergy.com'
team_owner: '!subteam^S7K9CR63D' #@datateam
description: >
This table gives one row per truncated month with the count
of customers that have created their first order within this month
Expand All @@ -10,4 +24,4 @@ models:
description: primary key
tests:
- unique
- not_null
- not_null
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
select
date_trunc('month', first_order) AS first_order_month
, count(*) AS number_customers
from {{ ref('wh_customers') }}
SELECT
DATE_TRUNC('month', cust.first_order) AS first_order_month
, COUNT(DISTINCT cust.customer_id) AS number_customers
FROM {{ ref('wh_customers') }} AS cust
40 changes: 31 additions & 9 deletions jaffle_shop/models/staging/src_seed/_models.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
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

- name: stg_customers
description: staging layer for all customers, PII hashed
columns:
- name: customer_id
description: Primary Key
tests:
- unique
- not_null
- name: first_name_hash
tests:
- dbt_expectations.expect_column_to_exist
- name: last_name_hash
tests:
- dbt_expectations.expect_column_to_exist

- name: stg_orders
description: staging layer for all orders
columns:
Expand All @@ -26,12 +57,3 @@ 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
18 changes: 0 additions & 18 deletions jaffle_shop/models/staging/src_seed/sensitive/_models.yml

This file was deleted.

21 changes: 11 additions & 10 deletions jaffle_shop/models/staging/src_seed/stg_orders.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
with source as (
WITH source AS (

{#-
Normally we would select from the table here, but we are using seeds to load
our data in this project
#}
select * from {{ ref('raw_orders') }}
SELECT * FROM {{ ref('raw_orders') }}

),

renamed as (
renamed AS (

select
id as order_id,
user_id as customer_id,
order_date,
status
SELECT
id AS order_id
, user_id AS customer_id
, order_date
, status

from source
FROM source

)

select * from renamed
SELECT *
FROM renamed
22 changes: 11 additions & 11 deletions jaffle_shop/models/staging/src_seed/stg_payments.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
with source as (
WITH source AS (

{#-
Normally we would select from the table here, but we are using seeds to load
our data in this project
#}
select * from {{ ref('raw_payments') }}
SELECT * FROM {{ ref('raw_payments') }}

),

renamed as (

select
id as payment_id,
order_id,
payment_method,
renamed AS (

SELECT
id AS payment_id
, order_id
, payment_method
-- `amount` is currently stored in cents, so we convert it to dollars
amount / 100 as amount_dollars
, amount / 100 AS amount_dollars

from source
FROM source

)

select * from renamed
SELECT *
FROM renamed
85 changes: 15 additions & 70 deletions jaffle_shop/models/warehouse/wh_customers.sql
Original file line number Diff line number Diff line change
@@ -1,70 +1,15 @@
with customers as (

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

),

orders as (

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

),

payments as (

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

),

customer_orders as (

select
customer_id,

min(order_date) as first_order,
max(order_date) as most_recent_order,
count(order_id) as number_of_orders
from orders

group by customer_id

),

customer_payments as (

select
orders.customer_id,
sum(amount) as total_amount

from payments

left join orders on
payments.order_id = orders.order_id

group by orders.customer_id

),

final as (

select
customers.customer_id,
customers.first_name,
customers.last_name,

customer_orders.first_order,
customer_orders.most_recent_order,
customer_orders.number_of_orders,
customer_payments.total_amount as customer_lifetime_value

from customers

left join customer_orders
on customers.customer_id = customer_orders.customer_id

left join customer_payments
on customers.customer_id = customer_payments.customer_id

)

select * from final
SELECT
orders.customer_id
, customers.first_name_hash
, customers.last_name_hash
, MIN(orders.order_date) AS first_order
, MAX(orders.order_date) AS most_recent_order
, COUNT(orders.order_id) AS number_of_orders
, SUM(payments.amount) AS customer_lifetime_value
FROM {{ ref('stg_orders') }} orders
LEFT JOIN {{ ref('stg_customers') }} customers
ON orders.customer_id = customers.customer_id
LEFT JOIN {{ ref('stg_payments') }} payments
ON orders.order_id = payments.order_id

GROUP BY orders.customer_id, customers.first_name_hash, customers.last_name_hash
Loading