-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal_project_deliverable_3
318 lines (256 loc) · 7.37 KB
/
final_project_deliverable_3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
### Transform (dbt) ###
- Open VSCode
- File > Open > Select your project (lastname_DW)
- On the top bar of the application, select Terminal > New Terminal
- This will open a terminal in the directory of your project within VSCode
- Right click on the models directory and create a new folder inside of it. (Be careful not to create it inside of the example directory.)
- Call this new folder `samssubssandwhichs`
- Right click on the folder samssubssandwhichs and create a new file. Name this file `_src_samssubssandwhichs.yml`
- Populate the following code within _src_samssubssandwhichs.yml
```
version: 2
sources:
- name: SAMSSUBSSANDWHICH
database: GROUP3_PROJECT
schema: SAMSSUBSSANDWHICH
tables:
- name: employee
- name: customer
- name: product
- name: date
- name: store
- name: ingredient
- name: inventory
- name: orders
- name: order_line
```
- If you need to make any changes to your Snowflake information in your dbt project you can change it by going to your dbt profile.yml file. You may need to change the schema.
- On a mac, this is located under your user directory. You have to click Shift + command + . in order to see hidden folders. The .dbt folder will appear and inside is profiles.yml
- On Windows, it's just in the user directory under the .dbt folder and the profiles.yml is inside.
- Once you have found the profiles.yml file you can open in a text editor, change the database to GROUP3_PROJECT or your target database
#### dim employee####
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_employee.sql`
- Populate the following code within ss_dim_employee.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
)
}}
SELECT
{{ dbt_utils.generate_surrogate_key(['employee_id', 'employee_first_name', 'employee_last_name']) }} as employee_key,
employee_pk,
employee_id,
employee_first_name,
employee_last_name,
employee_birthdate
FROM {{ source('SAMSSUBSSANDWHICH', 'employee') }}
'''
- Now run the following
'''
dbt run -m ss_dim_employee
'''
#### dim customer####
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_customer.sql`
- Populate the following code within ss_dim_customer.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
)
}}
select
{{ dbt_utils.generate_surrogate_key(['customer_id', 'customer_first_name', 'customer_last_name']) }} as customer_key,
customer_pk,
customer_phone,
customer_birthdate,
customer_last_name,
customer_first_name
FROM {{ source('SAMSSUBSSANDWHICH', 'customer') }}
'''
- Now run the following
'''
dbt run -m ss_dim_customer
'''
#### dim date####
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_date.sql`
- Populate the following code within ss_dim_date.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
)
}}
with cte_date as (
{{ dbt_date.get_date_dimension("1990-01-01", "2050-12-31") }}
)
SELECT
date_day as date_key,
date_day,
day_of_week,
month_of_year,
month_name,
quarter_of_year,
year_number
from cte_date
'''
- Now run the following
'''
dbt run -m ss_dim_date
'''
'''
### dim ingredient ###
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_ingredient.sql`
- Populate the following code within ss_dim_ingredient.sql
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
) }}
SELECT
CAST(Null as INT) as ingredient_id,
CAST(Null as VARCHAR(255)) as ingredient_name,
CAST(Null as DECIMAL) as ingredient_height,
CAST(Null as DECIMAL) as ingredient_width,
CAST(Null as DECIMAL) as ingredient_length,
CAST(Null as DECIMAL) as ingredient_weight,
CAST(Null as VARCHAR(255)) as supplier_name
WHERE FALSE
'''
- Now run the following
'''
dbt run -m ss_dim_ingredient
'''
### dim orderline ###
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_orderline.sql`
- Populate the following code within ss_dim_orderline.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
)
}}
select
{{ dbt_utils.generate_surrogate_key(['order_line_id','order_number']) }} as order_line_key,
order_line_qty,
order_line_id,
order_number,
p.product_key,
order_line_price
FROM {{ source('SAMSSUBSSANDWHICH', 'order_line') }} ol
INNER JOIN {{ref('ss_dim_product')}} p on p.product_id = ol.product_id
'''
- Now run the following
'''
dbt run -m ss_dim_orderline
'''
### dim product ###
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_product.sql`
- Populate the following code within ss_dim_product.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
)
}}
select
{{ dbt_utils.generate_surrogate_key(['product_id', 'product_name']) }} as product_key,
product_id,
product_type,
product_name,
product_cost,
product_calories
FROM {{ source('SAMSSUBSSANDWHICH', 'product') }}
'''
- Now run the following
'''
dbt run -m ss_dim_product
'''
### dim store ###
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_store.sql`
- Populate the following code within ss_dim_store.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
)
}}
select
{{ dbt_utils.generate_surrogate_key(['store_id', 'store_state']) }} as store_key,
store_id,
store_pk,
store_address,
store_city,
store_state,
store_zip
FROM {{ source('SAMSSUBSSANDWHICH', 'store') }}
'''
- Now run the following
'''
dbt run -m ss_dim_store
'''
### dim inventory ###
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_inventory.sql`
- Populate the following code within ss_dim_inventory.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
) }}
SELECT
CAST(Null as INT) as inventory_id,
CAST(Null as DATE) as date_key,
CAST(Null as INT) as store_key,
CAST(Null as INT) as ingredient_id,
CAST(Null as INT) as ingredient_qty,
WHERE FALSE
'''
- Now run the following
'''
dbt run -m ss_fact_inventory
'''
### dim order ###
- Create a new file inside of the samssubssandwhichs directory called `ss_dim_order.sql`
- Populate the following code within ss_dim_order.sql
'''
{{ config(
materialized = 'table',
schema = 'dw_samssubsandwhichs'
) }}
SELECT
o.order_number,
o.order_method,
d.date_key,
c.customer_key,
s.stores_key,
e.employee_key,
o.order_total_price,
o.order_points_earned
FROM {{ source('SAMSSUBSSANDWHICH', 'orders') }} o
INNER JOIN {{ ref('ss_dim_customer') }} c ON o.customer_pk = c.customer_pk
INNER JOIN {{ ref('ss_dim_employee') }} e ON o.employee_pk = e.employee_pk
INNER JOIN {{ ref('ss_dim_store') }} s ON o.store_pk = s.store_pk
INNER JOIN {{ ref('ss_dim_date') }} d ON o.order_date = d.date_key
'''
- Now run the following
'''
dbt run -m ss_fact_order
'''
- Now create the _schema_samssubssandwhichs.yml file with the following code
'''
version: 2
models:
- name: ss_dim_employee
description: "Sams Employees Dimension"
- name: ss_dim_customer
description: "Sams Customer Dimension"
- name: ss_dim_date
description: "Sams Date Dimension"
- name: ss_dim_store
description: "Sams Store Dimension"
- name: ss_dim_ingredient
description: "Sams Ingredient Dimension"
- name: ss_fact_order
description: "Sams Order Fact"
- name: ss_fact_inventory
description: "Sams Inventory Fact"
'''