Skip to content

Commit b60c149

Browse files
authored
Update data-graph.md
1 parent ae3e85c commit b60c149

File tree

1 file changed

+103
-37
lines changed

1 file changed

+103
-37
lines changed

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

Lines changed: 103 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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
125+
data_graph {
119126
entity "account-entity" {
120127
name = "account"
121128
table_ref = "PRODUCTION.CUST.ACCOUNT"
122129
primary_key = "id"
123130
enrichment_enabled = true
124131
}
125132

133+
entity "cart-entity" {
134+
name = "cart"
135+
table_ref = "PRODUCTION.CUST.CART"
136+
primary_key = "id"
137+
}
138+
139+
# Define a profile entity
126140
profile {
127-
# Relationships are nested under the profile
141+
profile_folder = "PRODUCTION.segment"
142+
type = segment:materialized
143+
128144
}
129145
}
146+
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

@@ -152,10 +170,24 @@ Example:
152170

153171
```python
154172
data_graph {
155-
#define entities
173+
#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.
@@ -177,8 +211,11 @@ Example:
177211
data_graph {
178212
#define entities
179213

214+
#define profile
180215
profile {
181-
#define profile
216+
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,57 @@ 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+
249+
#define entities
250+
entity "account-entity" {
251+
name = "account"
252+
table_ref = "PRODUCTION.CUST.ACCOUNT"
253+
primary_key = "id"
254+
enrichment_enabled = true
255+
}
256+
257+
entity "cart-entity" {
258+
name = "cart"
259+
table_ref = "PRODUCTION.CUST.CART"
260+
primary_key = "id"
261+
}
262+
263+
#define profile
210264
profile {
211-
#define profile
212-
...
213-
#relate account to carts
265+
profile_folder = "PRODUCTION.segment"
266+
type = segment:materialized
267+
268+
relationship "user-accounts" {
269+
name = "Premium Accounts"
270+
related_entity = "account-entity"
271+
external_id {
272+
type = "email"
273+
join_key = "email_id"
274+
}
275+
276+
#relate account to Carts
214277
relationship "Carts" {
215278
name = "Shopping Carts"
216-
related_entity = "cart-entity"
217-
join_on = "account.id = cart.account_id"
279+
related_entity = "carts-entity"
280+
join_on = "account-entity.id = carts-entity.account_id"
218281
}
219282
}
283+
284+
}
220285
}
221286
}
222287

@@ -231,8 +296,8 @@ If you're relating entities with a junction table:
231296
| `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]`. |
232297
| `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]`. |
233298
| `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]`. |
299+
| `left_join_on` | Defines the relationship between the two entity tables: `[left entity slug].[column name] = [junction table column name]`. |
300+
| `right_join_on` | Defines the relationship between the two entity tables: `[junction table column name] = [right entity slug].[column name]`. |
236301

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

@@ -356,3 +421,4 @@ Editing the Data Graph may lead to errors with data consumers. If there’s a br
356421
## Next steps
357422

358423
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/).
424+

0 commit comments

Comments
 (0)