DataMapping@1
Node DataMapping@1 is used to map data from one field to another field or value based on configuration in the payload.
Adapter Prerequisites
Node Configuration
For fields path, targetPath, targetValueWriteMode, and targetValueKind, see Overview.
transformations:
- type: DataMapping@1
path: $.AlarmState # The path to the source field
targetPath: $.State # The path to the target field
targetValueWriteMode: Overwrite # The target value write mode, should be 'Overwrite' to overwrite the target value
sourceValueType: Int # The data type of the source field. Allowed values are: 'Int', 'String', 'Binary', 'Boolean', 'DateTime', 'Double', 'StringArray', 'IntArray', 'TimeSpan', 'Int64'
targetValueType: Int # The data type of the source field. Allowed values are: 'Int', 'String', 'Binary', 'Boolean', 'DateTime', 'Double', 'StringArray', 'IntArray', 'TimeSpan', 'Int64'
mappings: # The mappings that should be applied to the source field
- sourceValue: 0 # The source value that should be mapped
targetValue: 1 # The target value that should be written
description: "received -> normal" # A optional description of the mapping. will be added to the debug logs for better traceability
- sourceValue: 1
targetValue: 3
description: "acknowledged -> acknowledged"
Mapping whole arrays
The shape of path decides what the node does:
- A
paththat addresses one value (for example$.AlarmStateor$.rows[1].unit) maps that value and writes the result totargetPath, as described above. - A
paththat can address several values maps every addressed element in place, withoutForEach@1and without a script. This covers a wildcard ($.sd.Rows[*].Values[5]), a recursive descent ($..unit) and a filter ($.items[?(@.kind=='a')].unit).
transformations:
- type: DataMapping@1
path: $.sd.Rows[*].Values[5] # every Unit of every row of a GetStreamData@1 result
targetPath: $.sd.Rows[*].Values[5] # the same path, or leave targetPath out
sourceValueType: Int
targetValueType: String
mappings:
- sourceValue: 1
targetValue: kWh
- sourceValue: 2
targetValue: MWh
For a path with several matches:
targetPathmust be the same path or be left out. Any other value is rejected with an error that names the node and both paths, because the results have no single target.targetValueWriteMode,targetValueKindanddocumentModedo not apply to the in-place write: leave them at their defaults (Overwrite,Simple,Extend), any other value fails the node.- Elements that are
nullare skipped. Elements without a matching mapping stay as they are. Everything outside the matches is not touched. - A path that matches nothing logs a warning and the data flow continues.
- An element that cannot be read as
sourceValueTypefails the node; the error names the element by its position among the matches. The run is not atomic: the elements before the failing one are already mapped when the node fails. A failing node ends the data flow execution and its data is discarded. - The run writes one debug line (
Mapped N of M elements) instead of one per element.
note
The mapping of a whole array is about 1.3 times faster than a ForEach@1 with one DataMapping@1 per element (measured with 123,000 rows) and needs less memory. It replaces the loop and the script, it does not make very large arrays free.