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
[pkg/ottl] enhance flatten editor to resolve attribute key conflicts (#37006)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Introduce an option into `flatten()` editor to resolve conflicts in map
keys and avoid data loss. The original behavior is perserved
<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes#35793
---------
Signed-off-by: odubajDT <[email protected]>
Co-authored-by: Evan Bradley <[email protected]>
The `flatten` function flattens a `pcommon.Map` by moving items from nested maps to the root.
132
132
133
-
`target` is a path expression to a `pcommon.Map` type field. `prefix` is an optional string. `depth` is an optional non-negative int.
133
+
`target` is a path expression to a `pcommon.Map` type field. `prefix` is an optional string. `depth` is an optional non-negative int, `resolveConflicts` resolves the potential conflicts in the map keys by adding a number suffix starting with `0` from the first duplicated key.
134
+
134
135
135
136
For example, the following map
136
137
@@ -199,6 +200,46 @@ the result would be
199
200
200
201
A `depth` of `0` means that no flattening will occur.
201
202
203
+
If `resolveConflicts` is set to `true`, conflicts within the map will be resolved
204
+
205
+
```json
206
+
{
207
+
"address": {
208
+
"street": {
209
+
"number": "first",
210
+
},
211
+
"house": "1234",
212
+
},
213
+
"address.street": {
214
+
"number": ["second", "third"],
215
+
},
216
+
"address.street.number": "fourth",
217
+
"occupants": [
218
+
"user 1",
219
+
"user 2",
220
+
],
221
+
}
222
+
```
223
+
224
+
the result would be
225
+
226
+
```json
227
+
{
228
+
"address.street.number": "first",
229
+
"address.house": "1234",
230
+
"address.street.number.0": "second",
231
+
"address.street.number.1": "third",
232
+
"occupants": "user 1",
233
+
"occupants.0": "user 2",
234
+
"address.street.number.2": "fourth",
235
+
}
236
+
237
+
```
238
+
239
+
**Note:**
240
+
Please note that when the `resolveConflicts` parameter is set to `true`, the flattening of arrays is managed differently.
241
+
With conflict resolution enabled, arrays and any potentially conflicting keys are handled in a standardized manner. Specifically, a `.<number>` suffix is added to the first conflicting key, with the `number` incrementing for each additional conflict.
0 commit comments