You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/unify/data-graph/data-graph.md
+31-26Lines changed: 31 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,24 +145,26 @@ data_graph {
145
145
146
146
Now define your relationships across your entities. The Data Graph supports three types of relationships:
147
147
- Profile-to-entity relationship. This is the first level of relationships
148
-
- 1:manyrelationships
149
-
- Many:manyrelationships
148
+
- 1:manyrelationship
149
+
- Many:manyrelationship
150
150
151
-
All relationship types require you to define the `relationship` slug,`name`, and `related_entity`. Each type of relationship has unique `join_on` conditions.
151
+
All relationship types require you to define the relationship slug, label, and related entity. Each type of relationship has unique join on conditions.
|`relationship`| An immutable slug for the relationship, and will be treated as a delete if you make changes. The slug must be in all lowercase, and supports dashes or underscores (e.g. `user-account` or `user_account`) |
159
159
|`name`| A label displayed throughout your Segment space for Linked Events, Linked Audiences, etc. This name can be modified at any time |
160
160
|`related_entity`| References your already defined entity |
161
161
162
-
To define a profile-to-entity relationship, choose to join on one of the following:
163
-
**Option 1:** Use the `external_id` block to join the profile entity with `user_id`, `email`, or `phone` as the identifier on the entity table
162
+
To define a profile-to-entity relationship, choose to join on one of the following:
163
+
164
+
**Option 1 (Most common):** Use the `external_id` block to join the profile entity with `user_id`, `email`, or `phone` as the identifier on the entity table
164
165
-`type`: Identify the external ID type (`email`, `phone`, `user id`). This corresponds to the `external_id_type` column in your Profiles Sync `external_id_mapping` table
165
166
-`join_key`: This is the column on the entity table that you are matching to the external identifier
167
+
166
168
**Option 2:** Use the `traits` block to join with a profile trait on the entity table
167
169
-`name`: The trait name that corresponds to a column name in your Profiles Sync `profile_traits_updates` table
168
170
-`join_key`: This is the column on the entity table that you are matching to the trait
@@ -177,23 +179,24 @@ data_graph {
177
179
}
178
180
179
181
# Define additional entities...
180
-
182
+
183
+
# Note: Relationships are nested
181
184
profile {
182
185
profile_folder = "PRODUCTION.SEGMENT"
183
186
type = "segment:materialized"
184
187
185
-
#Relationships are nested
188
+
#Relate accounts table to the profile
186
189
relationship "user-accounts" {
187
190
name = "Premium Accounts"
188
191
related_entity = "account-entity"
189
192
190
-
# Option 1: Relate account to profile with an external ID
193
+
# Option 1: Join with an external ID block
191
194
external_id {
192
195
type = "email"
193
196
join_key = "EMAIL_ID"
194
197
}
195
198
196
-
# Option 2: Relate account to profile with a trait
199
+
# Option 2: Join with a trait block
197
200
trait {
198
201
name = "cust_id"
199
202
join_key = "ID"
@@ -204,7 +207,7 @@ data_graph {
204
207
```
205
208
206
209
#### Relationship #2: Define a 1:many relationship
207
-
To define a 1:manyrelationship, define the join on between the two entity tables.
210
+
For 1:manyrelationships, define the join on between the two entity tables using the spec below.
For many:many relationships, define the join on between the two entity tables with the `junction_table`.
252
+
253
+
> warning ""
254
+
> Attributes from a junction table are not referenceable via the Linked Audience Builder. If a marketer would like to filter upon a column on the junction table, you must define the junction as an entity and define a relationship.
|`relationship`| An immutable slug for the relationship, and will be treated as a delete if you make changes. The slug must be in all lowercase, and supports dashes or underscores (e.g. `user-account` or `user_account`) |
252
259
|`name`| A label displayed throughout your Segment space for Linked Events, Linked Audiences, etc. This name can be modified at any time |
253
260
|`related_entity`| References your already defined entity |
254
261
255
-
To define a many:many relationship, define the join on between the two entity tables with the `junction_table`.
256
-
> warning ""
257
-
> Attributes from a junction table are not referenceable via the Linked Audience Builder. If a marketer would like to filter upon a column on the junction table, you must define the junction as an entity and define a relationship.
|`table_ref`| Defines the fully qualified table reference to the join table.: `[database name].[schema name].[table name]` Segment flexibly supports tables, views and materialized views |
261
266
|`primary_key`| The unique identifier for the given table. Must be a column with unique values per row |
262
267
|`left_join_on`| Define the relationship between the left entity table and the junction table: `[left entity slug].[column name] = [junction table column name]`. `[schema].[table]` is implied within the junction table column name, so you do not need to define it again |
@@ -268,18 +273,18 @@ To define a many:many relationship, define the join on between the two entity ta
268
273
269
274
data_graph {
270
275
# Define entities
271
-
276
+
277
+
# Note: Relationships are nested
272
278
profile {
273
279
# Define profile
274
-
275
-
# Relationships are nested
280
+
276
281
relationship "user-accounts" {
277
282
...
278
283
279
284
relationship "user-carts" {
280
285
...
281
286
282
-
# Define many:many relationship by joining entity tables with junction table
287
+
# Define many:many relationship between carts and products
283
288
relationship "products" {
284
289
name = "Purchased Products"
285
290
related_entity = "product-entity"
@@ -292,7 +297,7 @@ data_graph {
292
297
}
293
298
}
294
299
}
295
-
}
300
+
}
296
301
}
297
302
298
303
```
@@ -404,12 +409,12 @@ A data consumer refers to a Segment feature (e.g. Linked Events, Linked Audience
404
409
- Under **Unify > Data Graph**, click the **Data consumers** tab
405
410
- Click into a node on the Data Graph preview and a side sheet will pop up with the list of data consumers for the respective relationship
406
411
407
-
### Edits that may cause breaking and potential breaking changes
412
+
### Understand changes that may cause breaking and potential breaking changes
408
413
409
414
Upon saving changes to your Data Graph, a modal will pop up to warn of breaking and/or potential breaking changes to your data consumers. You must acknowledge and click **Confirm and save**in order to proceed.
410
415
-**Definite breaking change**: Occurs when deleting an entity or relationship that is being referenced by a data consumer. Data consumers affected by breaking changes will fail on the next run. Note: The entity and relationship `slug` are immutable and treated as a delete if you make changes. You can modify the `label`.
411
416
-**Potential breaking change**: Editing the Data Graph may lead to errors with data consumers. If there’s a breaking change, the data consumer will fail on the next run. Unaffected data consumers will continue to work.
412
417
413
-
### Warehouse breaking changes
418
+
### Detect warehouse breaking changes
414
419
415
420
Segment has a service that regularly scans and monitors the Data Graph for changes that occur in your warehouse that may break components of the Data Graph and/or data consumers, such as when the table being referenced gets deleted from your warehouse, the primary key column no longer exists, etc. An alert banner will be displayed on the Data Graph landing page. The banner will be removed once the issues are resolved in your warehouse and/or the Data Graph.
0 commit comments