Skip to content

Element <mapping>

Purpose: Conditionally add or overwrite product fields during the ordered mapping phase.

Why: Use it to add or overwrite fields conditionally during the ordered transformation phase.

Example

1
<mapping if="risk_profile == 'High'" set="interest_rate = 0.15"/>

Decision guide

Business value: Keeps ordered source-to-target transformations explicit without hiding them in one large script.

  • Use when

    • A source row conditionally adds or overwrites one or more product fields.
  • Choose another approach when

    • Only validation is required or a field's value is already clear as a key script.
  • Prerequisites

    • Place mappings in the required evaluation order after source constraints.
  • Alternatives

    • Use key script for a field-local derivation. (See: <key>)
    • Use rule for an explicit in-context conditional action outside the mapping phase. (See: <rule>)

Complete examples

Filter, transform, and validate source rows in explicit phases

Use source constraints before transformation, mappings in document order, and target constraints only on the completed output row.

rule-pipeline/data/customers.json
1
2
3
4
5
6
[
  {"customer_id": "C-100", "active": true,  "income": 120000, "credit_score": 780},
  {"customer_id": "C-200", "active": false, "income": 90000,  "credit_score": 760},
  {"customer_id": "C-300", "active": true,  "income": 60000,  "credit_score": 700},
  {"customer_id": "C-400", "active": true,  "income": 18000,  "credit_score": 650}
]
rule-pipeline/datamimic.xml
1
2
3
4
5
6
7
8
9
<setup numProcess="1">
    <generate name="eligible_customers" count="4" source="data/customers.json" target="LogExporter">
        <sourceConstraints if="active == False" require="False"/>
        <mapping if="income >= 100000 and credit_score >= 750" set="segment = 'premium'"/>
        <mapping if="not (income >= 100000 and credit_score >= 750)" set="segment = 'standard'"/>
        <mapping if="True" set="monthly_budget = income / 12"/>
        <targetConstraints if="30000 > income" require="False"/>
    </generate>
</setup>

Rules and invalid combinations

E005 — Rule Eval Failed

Failed to evaluate {kind} '{expr}' for <{element_tag}>{descriptor}{cause_clause}

Why: A runtime error was classified in this top-level error category.

Resolution: Inspect the nested issue code and descriptor context for the actionable resolution.

Full rule

Allowed parents / Allowed children

Allowed parents: else, else-if, generate, if, iterate, nestedKey, while

Allowed children:

None

  • Structured Data and Rule Pipelines — Shows how composite output shapes and the ordered source-filter, mapping, and target-filter pipeline work together without hiding phase boundaries.

Attributes

Show all 2 attributes

if

Condition to evaluate.

required; string.

set

Expression or Python assignment applied when the condition is true.

required; string.