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

Fix repo #27

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

exposures:
- name: fnl_finance_orders_per_customer
description: Used in Inksacio app
type: application
url: https://inksacio.eks.octopus.engineering/my_certification_dashboard/
owner:
email: [email protected]
depends_on:
- ref('wh_customers')

models:
- name: fnl_finance_orders_per_customer
description: This table contains the total value of orders per customer
columns:
- name: customer_id
description: This is a unique identifier for a customer
tests:
- unique
- not_null
- name: customer_lifetime_value
description: This is the total value of orders for a customer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
customers.customer_id
, customers.customer_lifetime_value
FROM {{ ref('wh_customers') }} AS customers
23 changes: 23 additions & 0 deletions jaffle_shop/models/final/sales/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2

exposures:
- name: fnl_sales_newcustomers
description: Used in Inksacio app
type: application
url: https://inksacio.eks.octopus.engineering/my_certification_dashboard/
owner:
email: [email protected]
depends_on:
- ref('wh_customers')

models:
- name: fnl_sales_newcustomers
description: This table contains the number of new customers per month
columns:
- name: month_start_date
description: This is a date representing the start of a month
tests:
- unique
- not_null
- name: new_customer_count
description: This is the number of new customers in a given month
6 changes: 6 additions & 0 deletions jaffle_shop/models/final/sales/fnl_sales_newcustomers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
DATE_TRUNC('MONTH', customers.first_order) AS month_start_date
, COUNT(customers.customer_id) AS new_customer_count
FROM {{ ref('wh_customers') }} AS customers
GROUP BY DATE_TRUNC('MONTH', customers.first_order)
ORDER BY DATE_TRUNC('MONTH', customers.first_order) DESC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No 'order bys' :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok ! Yes thinking about it that makes sense as whatever uses the model can order if needed?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never hardcode in 'order bys' in models (downstream process can do that if necessary) this is just the because of the added processing required.
Order bys that are part of window functions are okay ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col2)

Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
version: 2

models:
- name: stg_customers_pii
columns:
- name: customer_id
tests:
- unique
evb123 marked this conversation as resolved.
Show resolved Hide resolved
- not_null
- name: first_name
meta:
sensitive: true
- name: last_name
meta:
sensitive: true
- name: stg_customers
columns:
- name: customer_id
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
columns:
Expand Down
4 changes: 4 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,4 @@
SELECT
{{ hash_sensitive_columns('stg_customers_pii') }}
FROM {{ ref('stg_customers_pii') }}

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
version: 2

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

- 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:
- name: customer_id
description: This is a unique identifier for a customer
tests:
- unique
- not_null

- name: first_name
description: Customer's first name. PII.

- name: last_name
description: Customer's last name. PII.

- name: first_name_hash
description: Customer's first name.
- name: last_name_hash
description: Customer's last name.
- name: first_order
description: Date (UTC) of a customer's first order

- name: most_recent_order
description: Date (UTC) of a customer's most recent order

Expand All @@ -29,7 +25,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 +40,7 @@ models:
tests:
- not_null
- relationships:
to: ref('customers')
to: ref('stg_customers')
field: customer_id

- name: order_date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ 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
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.