Map¶
Maps the input using a static key/value table embedded in the rule's parameters.
The first parameter is an array of two-entry arrays: the first entry is
the key the input must match, the second is the replacement value. The
rule accepts any input type; multiple key types can coexist in the map,
but every entry must produce the same output type. To match string input
the key may be a regular expression in //-notation.
Behaviour when the input matches no key:
- With a default value — the default is returned.
successfulMappingistrue. Downstream rules see the default, exactly as if it had been a successful mapping. - Without a default value — the input is passed through unchanged
and
successfulMappingis set tofalse. Inside a||chain that's the cue for the next conditional rule to fire. Outside a||chain the original input value flows on. This is a footgun: aSTRINGinput on aMapwhose values areINTwill write the literal string into a CDM integer field, which either errors out at the load boundary or inserts garbage depending on driver strictness.
The standard pattern for terminal Map rules (not part of a || chain)
is therefore Map([..., default_value) followed by an AssertNot(default_value)
— the default sentinel turns "no match" into a logged, skipped row
rather than a corrupted insert.
Parameters¶
- 1 —
mapMandatory — accepts: array -
An array of
[key, value]pairs. The input is matched against each key; the first match's value is returned. Keys may be any input type and may include regular expressions for string inputs. - 2 —
defaultOptional — accepts: any -
A default value used when no key matches. Its type must match the output type of the entries in the map.
Input type¶
DATEFLOATINTSTRING
Output type¶
The output type matches the output type of the entries in the map.
Requires¶
- At least one entry must exist in the mapping array.
- The inner arrays of the first parameter must each have two entries.
- All inner arrays must produce the same output type.
- A default value, if given, must match the output type of the inner arrays.
Examples¶
String to integer map
Integer to integer map with default
Regex string keys