Mapping a loop to a non-looping element - 8.0

Talend Data Mapper User Guide

Version
8.0
Language
English
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2024-03-28
Aggregate values from a loop into a non-looping element.

Before you begin

You have created a map with an input and output structure. This example uses the same map as in Mapping nested loops.

About this task

In this example, you want to configure the output TotalItems element to return the number of output PartNum elements in each Items loop, and the output TotalNotices element to return the number of output Num elements.

This map is available in Other Projects > Examples > Maps > Looping > LoopAggregate.

Procedure

  1. Optional: If you are using the map created in the previous example, drag the input PartNumber element to the output PartNum.
    Your map should look like this:
  2. Drag an AgCount function and drop it on the output TotalItems element.
  3. Drag the output PartNum on the AgCount.
    A loop expressions is required to provide context for the aggregation. In this case, a LoopCopy function is automatically added to indicate that this element should use the same looping as the PartNum element.
  4. Drag an AgCount function and drop it on the output TotalNotices element.
  5. Drag the output Num on the AgCount.
    A LoopCopy function is automatically added.

Results

The loops are aggregated, you can use the Test Run button to see the output based on the sample input file. In this example, the output looks like this:
<Notices>
  <Notice>
    <Num>1</Num>
    <Name>Francis Upton</Name>
    <Items>
      <PartNum>1A45</PartNum>
    </Items>
    <Items>
      <PartNum>2</PartNum>
    </Items>
    <TotalItems>2</TotalItems>
  </Notice>
  <Notice>
    <Num>2</Num>
    <Name>Francis Upton</Name>
    <Items>
      <PartNum>5TTT9</PartNum>
    </Items>
    <Items>
      <PartNum>123</PartNum>
    </Items>
    <TotalItems>2</TotalItems>
  </Notice>
  <Notice>
    <Num>2</Num>
    <Name>Martha Lyman</Name>
    <Items>
      <PartNum>K4223</PartNum>
    </Items>
    <Items>
      <PartNum>K4552</PartNum>
    </Items>
    <TotalItems>2</TotalItems>
  </Notice>
  <TotalNotices>3</TotalNotices>
</Notices>