Skip to content

Commit 866c78c

Browse files
Add new models and add _models.yml files and remove _sources files
fix _models file
1 parent b6772e5 commit 866c78c

11 files changed

+51
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
3+
models:
4+
- name: fnl_finance_customerreturnstotal
5+
description: >
6+
This table gives one row per customer, with the total of their completed returns,
7+
pending_returns and the sum of the 2
8+
columns:
9+
- name: customer_id
10+
description: primary key
11+
tests:
12+
- unique
13+
- not_null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% set return_states = ['returned', 'return_pending'] %}
2+
3+
select
4+
custs.customer_id
5+
6+
{% for return_state in return_states -%}
7+
, SUM(payments.amount_dollars) FILTER (WHERE orders.status =' {{ return_state }}') AS {{ return_state }}_amount_dollars
8+
{% endfor -%}
9+
10+
, SUM(payments.amount_dollars) AS sum_return_amount_dollars
11+
12+
from {{ ref('wh_orders') }} AS orders
13+
left join {{ ref('wh_customers') }} AS custs
14+
on custs.customer_id = orders.customer_id
15+
left join {{ ref('stg_payments') }} AS payments
16+
on payments.order_id = orders.order_id
17+
where orders.status IN ('returned', 'return_pending')
18+
GROUP BY customer_id
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
3+
models:
4+
- name: fnl_sales_newcustomerhistory
5+
description: >
6+
This table gives one row per truncated month with the count
7+
of customers that have created their first order within this month
8+
columns:
9+
- name: first_order_month
10+
description: primary key
11+
tests:
12+
- unique
13+
- not_null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
select
2+
date_trunc('month', first_order) AS first_order_month
3+
, count(*) AS number_customers
4+
from {{ ref('wh_customers') }}

jaffle_shop/models/intermediate/_models.yml

Whitespace-only changes.

jaffle_shop/models/staging/src_seed/_models.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version: 2
22

3+
models:
34
- name: stg_orders
45
columns:
56
- name: order_id

jaffle_shop/models/staging/src_seed/_sources.yml

Whitespace-only changes.

jaffle_shop/models/staging/src_seed/stg_payments.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ renamed as (
1616
payment_method,
1717

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

2121
from source
2222

File renamed without changes.

jaffle_shop/models/warehouse/customers.sql jaffle_shop/models/warehouse/wh_customers.sql

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ final as (
5151
customers.customer_id,
5252
customers.first_name,
5353
customers.last_name,
54+
5455
customer_orders.first_order,
5556
customer_orders.most_recent_order,
5657
customer_orders.number_of_orders,

0 commit comments

Comments
 (0)