Skip to content

Map

mapping category: mapping-table supports `||`

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. successfulMapping is true. 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 successfulMapping is set to false. 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: a STRING input on a Map whose values are INT will 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

1map Mandatory — 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.

2default Optional — 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

  • DATE
  • FLOAT
  • INT
  • STRING

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

Map([["F", 8532], ["M", 8507]])

Integer to integer map with default

Map([[1, 8532], [2, 8507]], 0)

Regex string keys

Map([[/F(emale)?/, 8532], [/M(ale)?/, 8507]])

See also

UsagiMap, VocabMap, VocabSourceId