Skip to content

Commit 20c1e54

Browse files
authored
Merge pull request #6880 from segmentio/data-graph-updates
Data Graph Updates
2 parents 6cc01ab + debf45b commit 20c1e54

File tree

1 file changed

+129
-64
lines changed

1 file changed

+129
-64
lines changed

src/unify/data-graph/data-graph.md

+129-64
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
[---
22
title: Data Graph
33
plan: unify
44
beta: true
@@ -7,9 +7,9 @@ redirect_from:
77
- '/unify/linked-profiles/data-graph'
88
---
99

10-
You can build a Data Graph that defines relationships between any entity data set in the warehouse and the Segment Profiles you send with Profiles Sync. Make this relational data accessible to marketers and business stakeholders to empower them with the data they need to create targeted and personalized customer engagements.
10+
You can build a Data Graph that defines relationships between any entity data set in the warehouse and the Segment Profiles you send with [Profiles Sync](/docs/unify/profiles-sync/overview/). Make this relational data accessible to marketers and business stakeholders to empower them with the data they need to create targeted and personalized customer engagements.
1111

12-
Using the Data Graph, you can reflect your business in your data model. The Data Graph enables businesses to map and understand the relationships between different datasets about their customers (accounts, subscriptions, households, products), and tie rich entity context back to the profile.
12+
Using the Data Graph, you can reflect your business in your data model. The Data Graph enables businesses to map and understand the relationships between different datasets about their customers (accounts, subscriptions, households, products), and tie rich entity context back to the profile.
1313

1414
> info ""
1515
> Data Graph currently only supports workspaces in the United States.
@@ -62,76 +62,94 @@ This should be a Unify space with Profiles Sync already set up.
6262

6363
## Step 3: Build your Data Graph
6464

65-
The Data Graph is a semantic layer that represents a subset of relevant business data that you'll use for audience targeting and personalization in downstream tools. Use the configuration language spec below to add models to build your Data Graph. The Data Graph currently supports 4 layers of depth, including the Profile entity. Warehouse schemas are case sensitive, so you'll need to reflect the schema, table, and column names based on how you case them in the warehouse.
65+
The Data Graph is a semantic layer that represents a subset of relevant business data that you'll use for audience targeting and personalization in downstream tools. Use the configuration language spec below to add models to build your Data Graph. The Data Graph currently supports 6 layers of depth, including the Profile entity. Warehouse schemas are case sensitive, so you'll need to reflect the schema, table, and column names based on how you case them in the warehouse.
6666

6767
To leverage the Data Graph auto-complete feature, begin typing or use the following keyboard shortcuts to autocomplete the profile_folder and table_ref properties.
6868

69-
- Mac: CtrlSpace
70-
- Windows: AltEsc
69+
- Mac: Ctrl + Space
70+
- Windows: Alt + Esc
7171

7272
### Define entities
7373

7474
Use the parameters, definitions, and examples below to help you define entities.
7575

76-
#### Profile
77-
78-
The profile is a special class of entity that is always defined at the top of the Data Graph, and there can only be one profile for a Data Graph. The profile entity corresponds to the Profiles Sync tables and models, such as profile traits.
76+
#### Entity
7977

80-
The parameters are:
78+
The first step in creating a Data Graph is to define your Entities. An entity is a stateful representation of a business object. The entity corresponds to a table in the warehouse.
8179

8280
| Parameters | Definition |
8381
| ----------- | --------------------------------------------------------------------- |
84-
| `profile_folder` | This is the fully qualified path of the folder or schema location for the profile tables. |
85-
| `type` | Identifies the materialization methods of the profile tables (`segment:unmaterialized`, `segment:materialized`, `segment:dbt`). **Note:** Leveraging materialized profile tables optimizes warehouse compute costs. |
82+
| `entity` | A unique slug for the entity, which is immutable and treated as a delete if you make changes. The slug must be in all lowercase, and supports dashes or underscores (for example, `account-entity` or `account_entity`). |
83+
| `name` | A unique label that displays throughout your Segment space. |
84+
| `table_ref` | Defines the table reference. In order to specify a connection to your table in Snowflake, a fully qualified table reference is required: `[database name].[schema name].[table name]`. |
85+
| `primary_key` | The unique identifier for the given table. Should be a column with unique values per row. |
86+
| (Optional) `enrichment_enabled = true` | Indicates if you plan to also reference the entity table for [Linked Events](/docs/unify/data-graph/linked-events/). |
8687

8788
Example:
8889

8990
```python
90-
# Define a profile entity
91+
# Define an entity and optionally indicate if the entity will be referenced for Linked Events (event enrichment)
9192

92-
profile {
93-
profile_folder = "PRODUCTION.segment"
94-
type = segment:materialized
95-
93+
data_graph {
94+
# Entities are nested under the data_graph
95+
entity "account-entity" {
96+
name = "account"
97+
table_ref = "PRODUCTION.CUST.ACCOUNT"
98+
primary_key = "id"
99+
enrichment_enabled = true
100+
}
101+
102+
entity "cart-entity" {
103+
name = "cart"
104+
table_ref = "PRODUCTION.CUST.CART"
105+
primary_key = "id"
106+
}
96107
}
97108
```
98109

99-
#### Entity
110+
#### Profile
100111

101-
An entity is a stateful representation of a business object. The entity corresponds to a table in the warehouse that represents the entity.
112+
Next, we define a Profile block, a special class of Entity that represents Segment Profiles. There can only be one profile for a Data Graph. The profile entity corresponds to the Profiles Sync tables and models, such as profile traits.
102113

114+
The parameters are:
103115

104116
| Parameters | Definition |
105117
| ----------- | --------------------------------------------------------------------- |
106-
| `entity` | A unique slug for the entity, which is immutable and treated as a delete if you make changes. The slug must be in all lowercase, and supports dashes or underscores (for example, `account-entity` or `account_entity`). |
107-
| `name` | A unique label that displays throughout your Segment space. |
108-
| `table_ref` | Defines the table reference. In order to specify a connection to your table in Snowflake, a fully qualified table reference is required: `[database name].[schema name].[table name]`. |
109-
| `primary_key` | The unique identifier for the given table. Should be a column with unique values per row. |
110-
| (Optional) `enrichment_enabled = true` | Indicates if you plan to also reference the entity table for [Linked Events](/docs/unify/data-graph/linked-events/). |
118+
| `profile_folder` | This is the fully qualified path of the folder or schema location for the profile tables. |
119+
| `type` | Identifies the materialization methods of the profile tables (segment:unmaterialized, segment:materialized) as defined in your Profiles Sync configuration. E.g. utilize segment:materialized if you are synching Profiles Materialized Tables. Note: Leveraging materialized profile tables optimizes warehouse compute costs. |
111120

112121
Example:
113122

114123
```python
115-
# Define an entity and optionally indicate if the entity will be referenced for Linked Events (event enrichment)
116124

117-
data_graph {
118-
# Entities are nested under the data_graph
119-
entity "account-entity" {
120-
name = "account"
121-
table_ref = "PRODUCTION.CUST.ACCOUNT"
122-
primary_key = "id"
123-
enrichment_enabled = true
125+
data_graph {
126+
entity "account-entity" {
127+
name = "account"
128+
table_ref = "PRODUCTION.CUST.ACCOUNT"
129+
primary_key = "id"
130+
enrichment_enabled = true
131+
}
132+
133+
entity "cart-entity" {
134+
name = "cart"
135+
table_ref = "PRODUCTION.CUST.CART"
136+
primary_key = "id"
137+
}
138+
139+
# Define a profile entity
140+
profile {
141+
profile_folder = "PRODUCTION.segment"
142+
type = segment:materialized
143+
144+
}
124145
}
125146

126-
profile {
127-
# Relationships are nested under the profile
128-
}
129-
}
147+
130148
```
131149

132150
### Relate entities
133151

134-
Use the following relationship, parameters, and examples to help you relate entities.
152+
Next, relate Profiles to Entities to model relationships between your Profiles and business datasets. Use the following relationship, parameters, and examples to help you relate entities.
135153

136154
#### Relate Entity to Profile
137155

@@ -153,9 +171,23 @@ Example:
153171
```python
154172
data_graph {
155173
#define entities
174+
entity "account-entity" {
175+
name = "account"
176+
table_ref = "PRODUCTION.CUST.ACCOUNT"
177+
primary_key = "id"
178+
enrichment_enabled = true
179+
}
180+
181+
entity "cart-entity" {
182+
name = "cart"
183+
table_ref = "PRODUCTION.CUST.CART"
184+
primary_key = "id"
185+
}
156186

187+
#define profile
157188
profile {
158-
#define profile
189+
profile_folder = "PRODUCTION.segment"
190+
type = segment:materialized
159191

160192
#Option 1: Relate account to profile with an external ID
161193
relationship "user-accounts" {
@@ -166,6 +198,8 @@ data_graph {
166198
join_key = "email_id"
167199
}
168200
}
201+
}
202+
}
169203
```
170204
**2. With a `trait`**: Define a profile trait that will be used to join the profile with your entity.
171205
- `name`: The trait name that corresponds to a column name in your `profile_traits_updates` table.
@@ -176,9 +210,12 @@ Example:
176210

177211
data_graph {
178212
#define entities
213+
....
179214

215+
#define profile
180216
profile {
181-
#define profile
217+
profile_folder = "PRODUCTION.segment"
218+
type = segment:materialized
182219

183220
#Option 2: relate account to profile with a trait`
184221
relationship: "user-accounts" {
@@ -194,29 +231,55 @@ data_graph {
194231
```
195232

196233
#### Relate between entities
234+
Finally, define relationships between Entities nested within the Profiles block.
197235

198236
| Parameters | Definition |
199237
| ----------- | --------------------------------------------------------------------- |
200238
| `relationship` | A unique slug for the relationship, which is immutable and treated as a delete if you make changes. The slug must be in all lowercase and will support dashes or underscores (for example, `user-account` or `user_account`). |
201239
| `name` | A unique label that displays throughout your Segment space. |
202240
| `related_entity` | References your already defined entity. |
203-
| `join_on` | Defines relationships between two entity tables `[lefty entity name].[column name] = [right entity name].[column name]`. Note that the entity name is a reference to the alias provided in the config and doesn't need to be the fully qualified table name. |
241+
| `join_on` | Defines relationships between two entity tables `[lefty entity slug].[column name] = [right entity slug].[column name]`. Note that the entity slug is a reference to the alias provided in the config and doesn't need to be the fully qualified table name. |
204242

205243
Example:
206244

207245
```py
208246
data_graph {
209247
#define entities
248+
entity "account-entity" {
249+
name = "account"
250+
table_ref = "PRODUCTION.CUST.ACCOUNT"
251+
primary_key = "id"
252+
enrichment_enabled = true
253+
}
254+
255+
entity "cart-entity" {
256+
name = "cart"
257+
table_ref = "PRODUCTION.CUST.CART"
258+
primary_key = "id"
259+
}
260+
261+
#define profile
210262
profile {
211-
#define profile
212-
...
213-
#relate account to carts
263+
profile_folder = "PRODUCTION.segment"
264+
type = segment:materialized
265+
266+
relationship "user-accounts" {
267+
name = "Premium Accounts"
268+
related_entity = "account-entity"
269+
external_id {
270+
type = "email"
271+
join_key = "email_id"
272+
}
273+
274+
#relate account to Carts
214275
relationship "Carts" {
215276
name = "Shopping Carts"
216-
related_entity = "cart-entity"
217-
join_on = "account.id = cart.account_id"
277+
related_entity = "carts-entity"
278+
join_on = "account-entity.id = carts-entity.account_id"
218279
}
219280
}
281+
282+
}
220283
}
221284
}
222285

@@ -231,8 +294,8 @@ If you're relating entities with a junction table:
231294
| `junction_table` | Defines the table reference to the join table. In order to specify a connection to your table in Snowflake, a fully qualified table reference is required: `[database name].[schema name].[table name]`. |
232295
| `table_ref` | Defines the table reference to the join table. In order to specify a connection to your table in Snowflake, a fully qualified table reference is required: `[database name].[schema name].[table name]`. |
233296
| `primary_key` | The unique identifier on the join table, and should be a column with unique values per row. |
234-
| `left_join_on` | Defines the relationship between the two entity tables: `[left entity name].[column name] = [junction table column name]`. |
235-
| `right_join_on` | Defines the relationship between the two entity tables: `[junction table column name] = [right entity name].[column name]`. |
297+
| `left_join_on` | Defines the relationship between the two entity tables: `[left entity slug].[column name] = [junction table column name]`. |
298+
| `right_join_on` | Defines the relationship between the two entity tables: `[junction table column name] = [right entity slug].[column name]`. |
236299

237300
**Note:** `schema.table` is implied within the junction table column name and doesn't need to be provided.
238301

@@ -245,6 +308,7 @@ Example:
245308

246309
data_graph {
247310
#define entities
311+
248312
profile {
249313
#define profile
250314
...
@@ -291,26 +355,26 @@ data_graph {
291355
join_key = "email_id"
292356
}
293357

294-
#relate carts to account
295-
relationship "user-carts" {
296-
name = "Shopping Carts"
297-
related_entity = "cart-entity"
298-
join_on = "ACCOUNT.ID = CART.ACCOUNT_ID"
299-
300-
#relate carts to products with a junction table
301-
relationship "products" {
302-
name = "Purchased Products"
303-
related_entity = "product-entity"
304-
junction_table {
305-
primary_key = "id"
306-
table_ref = "PRODUCTION.CUSTOMER.CART_PRODUCT"
307-
left_join_on = "CART.ID = CART_ID"
308-
#schema.table is implied within the cart_id key
309-
right_join_on = "PRODUCT_ID = PRODUCT.SKU"
310-
}
358+
#relate carts to account
359+
relationship "user-carts" {
360+
name = "Shopping Carts"
361+
related_entity = "cart-entity"
362+
join_on = "ACCOUNT.ID = CART.ACCOUNT_ID"
363+
364+
#relate carts to products with a junction table
365+
relationship "products" {
366+
name = "Purchased Products"
367+
related_entity = "product-entity"
368+
junction_table {
369+
primary_key = "id"
370+
table_ref = "PRODUCTION.CUSTOMER.CART_PRODUCT"
371+
left_join_on = "CART.ID = CART_ID"
372+
#schema.table is implied within the cart_id key
373+
right_join_on = "PRODUCT_ID = PRODUCT.SKU"
311374
}
312375
}
313376
}
377+
}
314378
}
315379

316380
#define account, product, and cart entities
@@ -356,3 +420,4 @@ Editing the Data Graph may lead to errors with data consumers. If there’s a br
356420
## Next steps
357421

358422
After you've set up your Data Graph, get started with [Linked Events](/docs/unify/data-graph/linked-events/) and [Linked Audiences](/docs/engage/audiences/linked-audiences/).
423+

0 commit comments

Comments
 (0)