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: articles/iot-operations/connect-to-cloud/concept-dataflow-conversions.md
+100-8Lines changed: 100 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: PatAltimore
5
5
ms.author: patricka
6
6
ms.subservice: azure-data-flows
7
7
ms.topic: concept-article
8
-
ms.date: 08/03/2024
8
+
ms.date: 10/30/2024
9
9
10
10
#CustomerIntent: As an operator, I want to understand how to use dataflow conversions to transform data.
11
11
ms.service: azure-iot-operations
@@ -19,6 +19,19 @@ You can use dataflow conversions to transform data in Azure IoT Operations. The
19
19
20
20
The dataflow conversion element is used to compute values for output fields:
21
21
22
+
# [Bicep](#tab/bicep)
23
+
24
+
```bicep
25
+
inputs: [
26
+
'*.Max' // - $1
27
+
'*.Min' // - $2
28
+
]
29
+
output: 'ColorProperties.*'
30
+
expression: '($1 + $2) / 2'
31
+
```
32
+
33
+
# [Kubernetes](#tab/kubernetes)
34
+
22
35
```yaml
23
36
- inputs:
24
37
- *.Max # - $1
@@ -27,6 +40,8 @@ The dataflow conversion element is used to compute values for output fields:
27
40
expression: ($1 + $2) / 2
28
41
```
29
42
43
+
---
44
+
30
45
There are several aspects to understand about conversions:
31
46
32
47
* **Reference to input fields:** How to reference values from input fields in the conversion formula.
@@ -38,6 +53,21 @@ There are several aspects to understand about conversions:
38
53
39
54
In conversions, formulas can operate on static values like a number such as *25* or parameters derived from input fields. A mapping defines these input fields that the formula can access. Each field is referenced according to its order in the input list:
40
55
56
+
# [Bicep](#tab/bicep)
57
+
58
+
```bicep
59
+
inputs: [
60
+
'*.Max'// - $1
61
+
'*.Min'// - $2
62
+
'*.Mid.Avg'// - $3
63
+
'*.Mid.Mean'// - $4
64
+
]
65
+
output: 'ColorProperties.*'
66
+
expression: '($1, $2, $3, $4)'
67
+
```
68
+
69
+
# [Kubernetes](#tab/kubernetes)
70
+
41
71
```yaml
42
72
- inputs:
43
73
- *.Max # - $1
@@ -48,6 +78,8 @@ In conversions, formulas can operate on static values like a number such as *25*
48
78
expression: ($1, $2, $3, $4)
49
79
```
50
80
81
+
---
82
+
51
83
In this example, the conversion results in an array containing the values of `[Max, Min, Mid.Avg, Mid.Mean]`. The comments in the YAML file (`# - $1`, `# - $2`) are optional, but they help to clarify the connection between each field property and its role in the conversion formula.
52
84
53
85
## Data types
@@ -125,32 +157,75 @@ Arrays can be processed by using aggregation functions to compute a single value
125
157
126
158
```json
127
159
{
128
-
"Measurements": [2.34, 12.3, 32.4]
160
+
"Measurements": [2.34, 12.3, 32.4]
129
161
}
130
162
```
131
163
132
164
With the mapping:
133
165
166
+
# [Bicep](#tab/bicep)
167
+
168
+
```bicep
169
+
inputs: [
170
+
'Measurements' // - $1
171
+
]
172
+
output: 'Measurement'
173
+
expression: 'min($1)'
174
+
```
175
+
176
+
# [Kubernetes](#tab/kubernetes)
177
+
134
178
```yaml
135
179
- inputs:
136
180
- Measurements # - $1
137
181
output: Measurement
138
182
expression: min($1)
139
183
```
140
184
185
+
---
186
+
141
187
This configuration selects the smallest value from the `Measurements` array for the output field.
142
188
143
189
It's also possible to use functions that result in a new array:
144
190
191
+
# [Bicep](#tab/bicep)
192
+
193
+
```bicep
194
+
inputs: [
195
+
'Measurements' // - $1
196
+
]
197
+
output: 'Measurements'
198
+
expression: 'take($1, 10)' // taking at max 10 items
199
+
```
200
+
201
+
# [Kubernetes](#tab/kubernetes)
202
+
145
203
```yaml
146
204
- inputs:
147
205
- Measurements # - $1
148
206
output: Measurements
149
207
expression: take($1, 10) # taking at max 10 items
150
208
```
151
209
210
+
---
211
+
152
212
Arrays can also be created from multiple single values:
153
213
214
+
# [Bicep](#tab/bicep)
215
+
216
+
```bicep
217
+
inputs: [
218
+
'minimum' // - - $1
219
+
'maximum' // - - $2
220
+
'average' // - - $3
221
+
'mean' // - - $4
222
+
]
223
+
output: 'stats'
224
+
expression: '($1, $2, $3, $4)'
225
+
```
226
+
227
+
# [Kubernetes](#tab/kubernetes)
228
+
154
229
```yaml
155
230
- inputs:
156
231
- minimum # - - $1
@@ -161,6 +236,8 @@ Arrays can also be created from multiple single values:
161
236
expression: ($1, $2, $3, $4)
162
237
```
163
238
239
+
---
240
+
164
241
This mapping creates an array that contains the minimum, maximum, average, and mean.
165
242
166
243
### Missing value
@@ -174,11 +251,11 @@ Example mapping that uses a missing value:
174
251
175
252
```json
176
253
{
177
-
"Employment": {
178
-
"Position": "Analyst",
179
-
"BaseSalary": 75000,
180
-
"WorkingHours": "Regular"
181
-
}
254
+
"Employment": {
255
+
"Position": "Analyst",
256
+
"BaseSalary": 75000,
257
+
"WorkingHours": "Regular"
258
+
}
182
259
}
183
260
```
184
261
@@ -194,14 +271,29 @@ The input record contains the `BaseSalary` field, but possibly that's optional.
194
271
195
272
A mapping can check if the field is present in the input record. If the field is found, the output receives that existing value. Otherwise, the output receives the value from the context dataset. For example:
196
273
274
+
# [Bicep](#tab/bicep)
275
+
276
+
```bicep
277
+
inputs: [
278
+
'BaseSalary' // - - - - - - - - - - - $1
279
+
'$context(position).BaseSalary' // - $2
280
+
]
281
+
output: 'BaseSalary'
282
+
expression: 'if($1 == (), $2, $1)'
283
+
```
284
+
285
+
# [Kubernetes](#tab/kubernetes)
286
+
197
287
```yaml
198
288
- inputs:
199
289
- BaseSalary # - - - - - - - - - - $1
200
-
- $context(position).BaseSalary # - $2
290
+
- $context(position).BaseSalary # - $2
201
291
output: BaseSalary
202
292
expression: if($1 == (), $2, $1)
203
293
```
204
294
295
+
---
296
+
205
297
The `conversion` uses the `if` function that has three parameters:
206
298
207
299
* The first parameter is a condition. In the example, it checks if the `BaseSalary` field of the input field (aliased as `$1`) is the missing value.
Copy file name to clipboardExpand all lines: articles/iot-operations/connect-to-cloud/concept-dataflow-enrich.md
+104-3Lines changed: 104 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: PatAltimore
5
5
ms.author: patricka
6
6
ms.subservice: azure-data-flows
7
7
ms.topic: concept-article
8
-
ms.date: 08/13/2024
8
+
ms.date: 10/30/2024
9
9
10
10
#CustomerIntent: As an operator, I want to understand how to create a dataflow to enrich data sent to endpoints.
11
11
ms.service: azure-iot-operations
@@ -34,20 +34,60 @@ For example, consider the following dataset with a few records, represented as J
34
34
35
35
The mapper accesses the reference dataset stored in the Azure IoT Operations [distributed state store (DSS)](../create-edge-apps/concept-about-state-store-protocol.md) by using a key value based on a *condition* specified in the mapping configuration. Key names in the DSS correspond to a dataset in the dataflow configuration.
36
36
37
+
# [Bicep](#tab/bicep)
38
+
39
+
```bicep
40
+
datasets: [
41
+
{
42
+
key: 'position',
43
+
inputs: [
44
+
'$source.Position' // - $1
45
+
'$context.Position' // - $2
46
+
],
47
+
expression: '$1 == $2'
48
+
}
49
+
]
50
+
```
51
+
52
+
# [Kubernetes](#tab/kubernetes)
53
+
37
54
```yaml
38
55
datasets:
39
56
- key: position
40
57
inputs:
41
-
- $source.Position # - $1
42
-
- $context.Position # -$2
58
+
- $source.Position #- $1
59
+
- $context.Position # -$2
43
60
expression: $1 == $2
44
61
```
45
62
63
+
---
64
+
46
65
When a new record is being processed, the mapper performs the following steps:
47
66
48
67
* **Data request:** The mapper sends a request to the DSS to retrieve the dataset stored under the key `Position`.
49
68
* **Record matching:** The mapper then queries this dataset to find the first record where the `Position` field in the dataset matches the `Position` field of the incoming record.
50
69
70
+
# [Bicep](#tab/bicep)
71
+
72
+
```bicep
73
+
{
74
+
inputs: [
75
+
'$context(position).WorkingHours' // - $1
76
+
]
77
+
output: 'WorkingHours'
78
+
}
79
+
{
80
+
inputs: [
81
+
'BaseSalary' // - - - - - - - - - - - - $1
82
+
'$context(position).BaseSalary' // - - $2
83
+
]
84
+
output: 'BaseSalary'
85
+
expression: 'if($1 == (), $2, $1)'
86
+
}
87
+
```
88
+
89
+
# [Kubernetes](#tab/kubernetes)
90
+
51
91
```yaml
52
92
- inputs:
53
93
- $context(position).WorkingHours # - $1
@@ -60,10 +100,37 @@ When a new record is being processed, the mapper performs the following steps:
60
100
expression: if($1 == (), $2, $1)
61
101
```
62
102
103
+
---
104
+
63
105
In this example, the `WorkingHours` field is added to the output record, while the `BaseSalary` is used conditionally only when the incoming record doesn't contain the `BaseSalary` field (or the value is `null` if it's a nullable field). The request for the contextualization data doesn't happen with every incoming record. The mapper requests the dataset and then it receives notifications from DSS about the changes, while it uses a cached version of the dataset.
64
106
65
107
It's possible to use multiple datasets:
66
108
109
+
# [Bicep](#tab/bicep)
110
+
111
+
```bicep
112
+
datasets: [
113
+
{
114
+
key: 'position'
115
+
inputs: [
116
+
'$source.Position' // - $1
117
+
'$context.Position' // - $2
118
+
],
119
+
expression: '$1 == $2'
120
+
}
121
+
{
122
+
key: 'permissions'
123
+
inputs: [
124
+
'$source.Position' // - $1
125
+
'$context.Position' // - $2
126
+
],
127
+
expression: '$1 == $2'
128
+
}
129
+
]
130
+
```
131
+
132
+
# [Kubernetes](#tab/kubernetes)
133
+
67
134
```yaml
68
135
datasets:
69
136
- key: position
@@ -79,16 +146,48 @@ datasets:
79
146
expression: $1 == $2
80
147
```
81
148
149
+
---
150
+
82
151
Then use the references mixed:
83
152
153
+
# [Bicep](#tab/bicep)
154
+
155
+
```bicep
156
+
inputs: [
157
+
'$context(position).WorkingHours' // - $1
158
+
'$context(permissions).NightShift' // - $2
159
+
]
160
+
```
161
+
162
+
# [Kubernetes](#tab/kubernetes)
163
+
84
164
```yaml
85
165
- inputs:
86
166
- $context(position).WorkingHours # - - $1
87
167
- $context(permission).NightShift # - - $2
88
168
```
89
169
170
+
---
171
+
90
172
The input references use the key of the dataset like `position` or `permission`. If the key in DSS is inconvenient to use, you can define an alias:
91
173
174
+
# [Bicep](#tab/bicep)
175
+
176
+
```bicep
177
+
datasets: [
178
+
{
179
+
key: 'datasets.parag10.rule42 as position'
180
+
inputs: [
181
+
'$source.Position' // - $1
182
+
'$context.Position' // - $2
183
+
],
184
+
expression: '$1 == $2'
185
+
}
186
+
]
187
+
```
188
+
189
+
# [Kubernetes](#tab/kubernetes)
190
+
92
191
```yaml
93
192
datasets:
94
193
- key: datasets.parag10.rule42 as position
@@ -98,4 +197,6 @@ datasets:
98
197
expression: $1 == $2
99
198
```
100
199
200
+
---
201
+
101
202
The configuration renames the dataset with the key `datasets.parag10.rule42` to `position`.
0 commit comments