Skip to main content

map

Syntax

- map:
- sub-op 1...
- sub-op 2...
- ...

Description

The map operation works on arrays, applying a separate chain of operations to every element in the array. The chain of sub-operations does not need to begin with a starting operation like source, and any number of operations can be chained together. The result of the map (the array of transformed elements) can be passed to further operations in the same variable (e.g. another expression or transform). Within sub-operations (for example in expression), you can reference both this (the current element) and external variables (other identifiers); when an external variable changes, the map is re-evaluated for affected elements.

If an array contains "arbitrary" elements, such that the array changes length or the elements don't have a fixed position within the array, avoid using operations that accumulate state. Stateful operations include average, count, off-delay`, and several more. State may be reset as the array changes, or may no longer match a source element if the element changes position.

Map can be useful when dealing with some data sources that can provide arrays of data on a single identifier. One example would be for synthesizing alarm codes when a data source only provides a list of alarm messages.

Examples

  alarm-codes:
- source: alarm-messages
- map:
- hash: md5
- max-length: 8
info

In the above example, alarm-messages is an identifier from another part of the adapter script.

The above example creates a synthesized list of alarm codes that correspond to a list of alarm messages. The map operation is used to apply a chain of two operations to each message. Within that chain, the hash operation creates a reasonably unique string from the message by calculating its MD5 hash. The max-length operation limits the value to 8 characters instead of the full 32 returned by the hash.