Splitting a loop in a DSQL map
Map multiple loops to a single loop.
Before you begin
- You have created an input and an output structure. You can use the JSON samples below to create your structures.
About this task
{
"bicycles": [
{
"make": "MBIKE",
"description": "27.5 inch electric mountain bike",
"color": "blue",
"price": 899.99
},
{
"make": "EBIKE",
"description": "Electric hybrid bike",
"color": "grey/green",
"price": 999.99
},
{
"make": "WBIKE",
"description": "Women's road bike",
"color": "white",
"price": 299.99
}
],
"scooters": [
{
"make": "ESCOOT",
"description": "Camou electric scooter",
"color": "black",
"price": 749
},
{
"make": "EVSCOOT",
"description": "Folding electric velocity+ scooter",
"color": "black",
"price": 599.99
},
{
"make": "KSCOOT",
"description": "24 volt kid scooter",
"color": "white",
"price": 299.99
}
]
}
The output structure looks like this:
{
"items": [
{
"make": "",
"description": "",
"price": ""
}
]
}
Procedure
Results
{
"items":[
{
"make":"MBIKE",
"description":"27.5 inch electric mountain bike",
"price":"899.99"
},
{
"make":"EBIKE",
"description":"Electric hybrid bike",
"price":"999.99"
},
{
"make":"WBIKE",
"description":"Women's road bike",
"price":"299.99"
},
{
"make":"ESCOOT",
"description":"Camou electric scooter",
"price":"749.0"
},
{
"make":"EVSCOOT",
"description":"Folding electric velocity+ scooter",
"price":"599.99"
},
{
"make":"KSCOOT",
"description":"24 volt kid scooter",
"price":"299.99"
}
]
}
You can also check the DSQL Script view to see
how this is handled with Data Shaping Query Language
using the UNION ALL clause. For more information, see the Talend
Data Shaping Language Reference Guide. In this example, the following script is
generated:
FROM itemsbycategory
SELECT {
items = (
FROM bicycles
SELECT {
make = make,
description = description,
price = price
}
UNION ALL
FROM scooters
SELECT {
make = make,
description = description,
price = price
}
)
}