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

Brewery shop Example #66

Open
wants to merge 6 commits into
base: duckdb
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
20 changes: 20 additions & 0 deletions models/customer_demographics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
with customers as (

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

),

demographics as (

select
gender,
count(customer_id) as total_customers,
avg(age) as average_age

from customers

group by gender

)

select * from demographics
2 changes: 2 additions & 0 deletions models/customers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ final as (
customers.customer_id,
customers.first_name,
customers.last_name,
customers.age,
customers.gender,
customer_orders.first_order,
customer_orders.most_recent_order,
customer_orders.number_of_orders,
Expand Down
20 changes: 20 additions & 0 deletions models/inventory_summary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
with inventory as (

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

),

summary as (

select
beer_type,
sum(quantity) as total_quantity,
sum(quantity * price) as total_value

from inventory

group by beer_type

)

select * from summary
1 change: 1 addition & 0 deletions models/orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final as (
orders.customer_id,
orders.order_date,
orders.status,
orders.beer_type,

{% for payment_method in payment_methods -%}

Expand Down
20 changes: 20 additions & 0 deletions models/sales_performance.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
with orders as (

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

),

sales as (

select
beer_type,
count(order_id) as total_orders,
sum(case when status = 'completed' then 1 else 0 end) as completed_orders

from orders

group by beer_type

)

select * from sales
16 changes: 16 additions & 0 deletions models/staging/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ models:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']

- name: stg_brewery_inventory
columns:
- name: inventory_id
tests:
- unique
- not_null
- name: beer_type
tests:
- not_null
- name: quantity
tests:
- not_null
- name: price
tests:
- not_null

- name: stg_payments
columns:
- name: payment_id
Expand Down
23 changes: 23 additions & 0 deletions models/staging/stg_brewery_inventory.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 {{ source('raw_brewery_inventory') }}

),

renamed as (

select
id as inventory_id,
beer_type,
quantity,
price

from source

)

select * from renamed
4 changes: 3 additions & 1 deletion models/staging/stg_customers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ renamed as (
select
id as customer_id,
first_name,
last_name
last_name,
age,
gender

from source

Expand Down
5 changes: 3 additions & 2 deletions models/staging/stg_orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ renamed as (

select
id as order_id,
user_id as customer_id,
customer_id,
order_date,
status
status,
beer_type

from source

Expand Down
3 changes: 1 addition & 2 deletions models/staging/stg_payments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ renamed as (
order_id,
payment_method,

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

from source

Expand Down
5 changes: 5 additions & 0 deletions seeds/raw_brewery_inventory.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,beer_type,quantity,price
1,IPA,100,5.00
2,Lager,150,4.50
3,Stout,200,6.00
4,Pilsner,120,4.75
202 changes: 101 additions & 101 deletions seeds/raw_customers.csv
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
id,first_name,last_name
1,Michael,P.
2,Shawn,M.
3,Kathleen,P.
4,Jimmy,C.
5,Katherine,R.
6,Sarah,R.
7,Martin,M.
8,Frank,R.
9,Jennifer,F.
10,Henry,W.
11,Fred,S.
12,Amy,D.
13,Kathleen,M.
14,Steve,F.
15,Teresa,H.
16,Amanda,H.
17,Kimberly,R.
18,Johnny,K.
19,Virginia,F.
20,Anna,A.
21,Willie,H.
22,Sean,H.
23,Mildred,A.
24,David,G.
25,Victor,H.
26,Aaron,R.
27,Benjamin,B.
28,Lisa,W.
29,Benjamin,K.
30,Christina,W.
31,Jane,G.
32,Thomas,O.
33,Katherine,M.
34,Jennifer,S.
35,Sara,T.
36,Harold,O.
37,Shirley,J.
38,Dennis,J.
39,Louise,W.
40,Maria,A.
41,Gloria,C.
42,Diana,S.
43,Kelly,N.
44,Jane,R.
45,Scott,B.
46,Norma,C.
47,Marie,P.
48,Lillian,C.
49,Judy,N.
50,Billy,L.
51,Howard,R.
52,Laura,F.
53,Anne,B.
54,Rose,M.
55,Nicholas,R.
56,Joshua,K.
57,Paul,W.
58,Kathryn,K.
59,Adam,A.
60,Norma,W.
61,Timothy,R.
62,Elizabeth,P.
63,Edward,G.
64,David,C.
65,Brenda,W.
66,Adam,W.
67,Michael,H.
68,Jesse,E.
69,Janet,P.
70,Helen,F.
71,Gerald,C.
72,Kathryn,O.
73,Alan,B.
74,Harry,A.
75,Andrea,H.
76,Barbara,W.
77,Anne,W.
78,Harry,H.
79,Jack,R.
80,Phillip,H.
81,Shirley,H.
82,Arthur,D.
83,Virginia,R.
84,Christina,R.
85,Theresa,M.
86,Jason,C.
87,Phillip,B.
88,Adam,T.
89,Margaret,J.
90,Paul,P.
91,Todd,W.
92,Willie,O.
93,Frances,R.
94,Gregory,H.
95,Lisa,P.
96,Jacqueline,A.
97,Shirley,D.
98,Nicole,M.
99,Mary,G.
100,Jean,M.
id,first_name,last_name,age,gender

Check notice on line 1 in seeds/raw_customers.csv

View check run for this annotation

Wiz Inc. (266a8a9c32) / Wiz Data Scanner

Sensitive data found: PII/Gender

Data Category: PII Data Classifier ID: BUILTIN-20 Sampled Examples: Key: gender, Value: *, Row Number: 10 Key: gender, Value: *, Row Number: 11 Key: gender, Value: *, Row Number: 12 Key: gender, Value: *, Row Number: 100 Key: gender, Value: *, Row Number: 101
1,Michael,P.,34,M
2,Shawn,M.,28,M
3,Kathleen,P.,45,F
4,Jimmy,C.,37,M
5,Katherine,R.,29,F
6,Sarah,R.,31,F
7,Martin,M.,40,M
8,Frank,R.,36,M
9,Jennifer,F.,27,F
10,Henry,W.,50,M
11,Fred,S.,33,M
12,Amy,D.,42,F
13,Kathleen,M.,38,F
14,Steve,F.,41,M
15,Teresa,H.,30,F
16,Amanda,H.,35,F
17,Kimberly,R.,39,F
18,Johnny,K.,32,M
19,Virginia,F.,46,F
20,Anna,A.,25,F
21,Willie,H.,48,M
22,Sean,H.,29,M
23,Mildred,A.,44,F
24,David,G.,31,M
25,Victor,H.,37,M
26,Aaron,R.,28,M
27,Benjamin,B.,34,M
28,Lisa,W.,26,F
29,Benjamin,K.,40,M
30,Christina,W.,33,F
31,Jane,G.,45,F
32,Thomas,O.,36,M
33,Katherine,M.,27,F
34,Jennifer,S.,38,F
35,Sara,T.,32,F
36,Harold,O.,41,M
37,Shirley,J.,30,F
38,Dennis,J.,39,M
39,Louise,W.,29,F
40,Maria,A.,35,F
41,Gloria,C.,47,F
42,Diana,S.,28,F
43,Kelly,N.,31,F
44,Jane,R.,33,F
45,Scott,B.,42,M
46,Norma,C.,37,F
47,Marie,P.,30,F
48,Lillian,C.,34,F
49,Judy,N.,29,F
50,Billy,L.,40,M
51,Howard,R.,36,M
52,Laura,F.,32,F
53,Anne,B.,45,F
54,Rose,M.,31,F
55,Nicholas,R.,28,M
56,Joshua,K.,33,M
57,Paul,W.,39,M
58,Kathryn,K.,27,F
59,Adam,A.,30,M
60,Norma,W.,41,F
61,Timothy,R.,35,M
62,Elizabeth,P.,29,F
63,Edward,G.,38,M
64,David,C.,32,M
65,Brenda,W.,44,F
66,Adam,W.,28,M
67,Michael,H.,36,M
68,Jesse,E.,31,M
69,Janet,P.,30,F
70,Helen,F.,47,F
71,Gerald,C.,34,M
72,Kathryn,O.,29,F
73,Alan,B.,40,M
74,Harry,A.,33,M
75,Andrea,H.,35,F
76,Barbara,W.,42,F
77,Anne,W.,30,F
78,Harry,H.,39,M
79,Jack,R.,28,M
80,Phillip,H.,34,M
81,Shirley,H.,31,F
82,Arthur,D.,45,M
83,Virginia,R.,37,F
84,Christina,R.,29,F
85,Theresa,M.,32,F
86,Jason,C.,36,M
87,Phillip,B.,30,M
88,Adam,T.,33,M
89,Margaret,J.,41,F
90,Paul,P.,38,M
91,Todd,W.,29,M
92,Willie,O.,35,M
93,Frances,R.,44,F
94,Gregory,H.,31,M
95,Lisa,P.,28,F
96,Jacqueline,A.,30,F
97,Shirley,D.,39,F
98,Nicole,M.,27,F
99,Mary,G.,33,F
100,Jean,M.,45,F
Loading