Skip to content

Commit

Permalink
Add new models and add _models.yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliotTaylor23 committed Jan 4, 2023
1 parent b6772e5 commit 46cada8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
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,18 @@
{% set return_states = ['returned', 'return_pending'] %}

select
custs.customer_id

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

, 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
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') }}
1 change: 1 addition & 0 deletions jaffle_shop/models/intermediate/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 2
2 changes: 1 addition & 1 deletion jaffle_shop/models/staging/src_seed/stg_payments.sql
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
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
File renamed without changes.

0 comments on commit 46cada8

Please sign in to comment.