-
Notifications
You must be signed in to change notification settings - Fork 4
/
thelook.model.lkml
321 lines (243 loc) · 7.15 KB
/
thelook.model.lkml
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
319
320
321
connection: "snowlooker"
label: "1) eCommerce with Event Data"
test: there_are_orders {
explore_source: order_items {
column: count {}
}
assert: there_is_data {
expression: ${order_items.count} > 0 ;;
}
}
include: "*.view" # include all the views
include: "*.dashboard" # include all the dashboards
datagroup: ecommerce_etl {
### Datagroups Allow you to sync cache and Persisted Derived Tables to events like ETL
sql_trigger: SELECT max(completed_at) FROM public.etl_jobs ;;
max_cache_age: "24 hours"
}
persist_with: ecommerce_etl
############ Base Explores #############
explore: order_items {
label: "(1) Orders, Items and Users"
view_name: order_items
join: order_facts {
view_label: "Orders"
relationship: many_to_one
sql_on: ${order_facts.order_id} = ${order_items.order_id} ;;
}
join: inventory_items {
#Left Join only brings in items that have been sold as order_item
type: full_outer
relationship: one_to_one
sql_on: ${inventory_items.id} = ${order_items.inventory_item_id} ;;
}
join: users {
relationship: many_to_one
sql_on: ${order_items.user_id} = ${users.id} ;;
}
join: user_order_facts {
view_label: "Users"
relationship: many_to_one
sql_on: ${user_order_facts.user_id} = ${order_items.user_id} ;;
}
join: products {
relationship: many_to_one
sql_on: ${products.id} = ${inventory_items.product_id} ;;
}
join: repeat_purchase_facts {
relationship: many_to_one
type: full_outer
sql_on: ${order_items.order_id} = ${repeat_purchase_facts.order_id} ;;
}
join: distribution_centers {
type: left_outer
sql_on: ${distribution_centers.id} = ${inventory_items.product_distribution_center_id} ;;
relationship: many_to_one
}
}
######### Event Data Explores #########
explore: events {
label: "(2) Web Event Data"
join: sessions {
sql_on: ${events.session_id} = ${sessions.session_id} ;;
relationship: many_to_one
}
join: session_landing_page {
from: events
sql_on: ${sessions.landing_event_id} = ${session_landing_page.event_id} ;;
fields: [simple_page_info*]
relationship: one_to_one
}
join: session_bounce_page {
from: events
sql_on: ${sessions.bounce_event_id} = ${session_bounce_page.event_id} ;;
fields: [simple_page_info*]
relationship: many_to_one
}
join: product_viewed {
from: products
sql_on: ${events.viewed_product_id} = ${product_viewed.id} ;;
relationship: many_to_one
}
join: users {
sql_on: ${sessions.session_user_id} = ${users.id} ;;
relationship: many_to_one
}
join: user_order_facts {
sql_on: ${users.id} = ${user_order_facts.user_id} ;;
relationship: one_to_one
view_label: "Users"
}
}
explore: sessions {
label: "(3) Web Session Data"
join: events {
sql_on: ${sessions.session_id} = ${events.session_id} ;;
relationship: one_to_many
}
join: product_viewed {
from: products
sql_on: ${events.viewed_product_id} = ${product_viewed.id} ;;
relationship: many_to_one
}
join: session_landing_page {
from: events
sql_on: ${sessions.landing_event_id} = ${session_landing_page.event_id} ;;
fields: [session_landing_page.simple_page_info*]
relationship: one_to_one
}
join: session_bounce_page {
from: events
sql_on: ${sessions.bounce_event_id} = ${session_bounce_page.event_id} ;;
fields: [session_bounce_page.simple_page_info*]
relationship: one_to_one
}
join: users {
relationship: many_to_one
sql_on: ${users.id} = ${sessions.session_user_id} ;;
}
join: user_order_facts {
relationship: many_to_one
sql_on: ${user_order_facts.user_id} = ${users.id} ;;
view_label: "Users"
}
}
######### Advanced Extensions #########
explore: affinity {
label: "(4) Affinity Analysis"
always_filter: {
filters: {
field: affinity.product_b_id
value: "-NULL"
}
}
join: product_a {
from: products
view_label: "Product A Details"
relationship: many_to_one
sql_on: ${affinity.product_a_id} = ${product_a.id} ;;
}
join: product_b {
from: products
view_label: "Product B Details"
relationship: many_to_one
sql_on: ${affinity.product_b_id} = ${product_b.id} ;;
}
}
explore: orders_with_share_of_wallet_application {
label: "(5) Share of Wallet Analysis"
extends: [order_items]
view_name: order_items
join: order_items_share_of_wallet {
view_label: "Share of Wallet"
}
}
explore: journey_mapping {
label: "(6) Customer Journey Mapping"
extends: [order_items]
view_name: order_items
join: repeat_purchase_facts {
relationship: many_to_one
sql_on: ${repeat_purchase_facts.next_order_id} = ${order_items.order_id} ;;
type: left_outer
}
join: next_order_items {
from: order_items
sql_on: ${repeat_purchase_facts.next_order_id} = ${next_order_items.order_id} ;;
relationship: many_to_many
}
join: next_order_inventory_items {
from: inventory_items
relationship: many_to_one
sql_on: ${next_order_items.inventory_item_id} = ${next_order_inventory_items.id} ;;
}
join: next_order_products {
from: products
relationship: many_to_one
sql_on: ${next_order_inventory_items.product_id} = ${next_order_products.id} ;;
}
}
explore: inventory_items{
label: "(7) Stock Analysis"
fields: [ALL_FIELDS*,-order_items.median_sale_price]
join: order_facts {
view_label: "Orders"
relationship: many_to_one
sql_on: ${order_facts.order_id} = ${order_items.order_id} ;;
}
join: order_items {
#Left Join only brings in items that have been sold as order_item
type: left_outer
relationship: many_to_one
sql_on: ${inventory_items.id} = ${order_items.inventory_item_id} ;;
}
join: users {
relationship: many_to_one
sql_on: ${order_items.user_id} = ${users.id} ;;
}
join: user_order_facts {
view_label: "Users"
relationship: many_to_one
sql_on: ${user_order_facts.user_id} = ${order_items.user_id} ;;
}
join: products {
relationship: many_to_one
sql_on: ${products.id} = ${inventory_items.product_id} ;;
}
join: repeat_purchase_facts {
relationship: many_to_one
type: full_outer
sql_on: ${order_items.order_id} = ${repeat_purchase_facts.order_id} ;;
}
join: distribution_centers {
type: left_outer
sql_on: ${distribution_centers.id} = ${inventory_items.product_distribution_center_id} ;;
relationship: many_to_one
}
}
explore: inventory_snapshot {
label: "(8) Historical Stock Snapshot Analysis"
join: trailing_sales_snapshot {
sql_on: ${inventory_snapshot.product_id}=${trailing_sales_snapshot.product_id}
AND ${inventory_snapshot.snapshot_date}=${trailing_sales_snapshot.snapshot_date};;
type: left_outer
relationship: one_to_one
}
join: products {
sql_on: ${inventory_snapshot.product_id} = ${products.id} ;;
relationship: many_to_one
}
join: distribution_centers {
sql_on: ${products.distribution_center_id}=${distribution_centers.id} ;;
relationship: many_to_one
}
}
explore: kitten_order_items {
label: "Order Items (Kittens)"
hidden: yes
extends: [order_items]
join: users {
view_label: "Kittens"
from: kitten_users
}
}