@@ -326,13 +326,25 @@ data_graph {
326
326
primary_key = " ID"
327
327
enrichment_enabled = true
328
328
}
329
+
330
+ entity " household-entity" {
331
+ name = " household"
332
+ table_ref = " PRODUCTION.CUST.HOUSEHOLD"
333
+ primary_key = " HOUSEHOLD_ID"
334
+ }
335
+
336
+ entity " subscription-entity" {
337
+ name = " subscription"
338
+ table_ref = " PRODUCTION.CUST.SUBSCRIPTION"
339
+ primary_key = " SUB_ID"
340
+ }
329
341
330
342
# Define the profile entity
331
343
profile {
332
344
profile_folder = " PRODUCTION.SEGMENT"
333
345
type = " segment: materialized"
334
346
335
- # Relate entity table to the profile by joining with an external ID block
347
+ # First branch - relate accounts table to the profile by joining with an external ID block
336
348
relationship " user-accounts" {
337
349
name = " Premium Accounts"
338
350
related_entity = " account-entity"
@@ -341,13 +353,13 @@ data_graph {
341
353
join_key = " EMAIL_ID"
342
354
}
343
355
344
- # Define 1:many relationship by joining left and right entity tables
356
+ # Define 1:many relationship between accounts and carts
345
357
relationship " user-carts" {
346
358
name = " Shopping Carts"
347
359
related_entity = " cart-entity"
348
360
join_on = " ACCOUNT.ID = CART.ACCOUNT_ID"
349
361
350
- # Define many:many relationship by joining left and right entity tables with a junction table
362
+ # Define many:many relationship between carts and products
351
363
relationship " products" {
352
364
name = " Purchased Products"
353
365
related_entity = " product-entity"
@@ -360,6 +372,21 @@ data_graph {
360
372
}
361
373
}
362
374
}
375
+
376
+ # Second branch - relate households table to the profile by joining with an external ID block
377
+ relationship " user-households" {
378
+ name = " Households"
379
+ related_entity = " household-entity"
380
+ external_id {
381
+ type = " email"
382
+ join_key = " EMAIL_ID"
383
+ }
384
+
385
+ # Define 1:many relationship between households and subscriptions
386
+ relationship " user-subscriptions" {
387
+ name = " Subscriptions"
388
+ related_entity = " subscription-entity"
389
+ join_on = " HOUSEHOLD.SUB_ID = SUBSCRIPTION.HOUSEHOLD_ID"
363
390
}
364
391
}
365
392
0 commit comments