Unrolling a loop in a DSQL map
Map multiple non-looping elements to the same looping element.
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
[
{
"make": "MBIKE",
"description": "27.5 inch electric mountain bike",
"tyres": {
"brand": "hutchinson",
"type": "Kraken 29x"
},
"seat": {
"brand": "ergon",
"type": "SR road sport gel"
},
"derailleur": {
"brand": "shimano",
"type": "ultegra D12"
}
},
{
"make": "EBIKE",
"description": "Electric hybrid bike",
"tyres": {
"brand": "vittoria",
"type": "Gravel terrend mix"
},
"seat": {
"brand": "selle italia",
"type": "SMTB black L3"
},
"derailleur": {
"brand": "sram",
"type": "GX 10"
}
},
{
"make": "WBIKE",
"description": "Women's road bike",
"tyres": {
"brand": "michelin",
"type": "power cup flex"
},
"seat": {
"brand": "xlc",
"type": "geltech ergo"
},
"derailleur": {
"brand": "ceramicspeed",
"type": "Eagle EAX"
}
}
]
The output structure looks like this:
[
{
"make": "",
"description": "",
"accessories": [
{
"category": "",
"brand": "",
"type": ""
}
]
}
]
Procedure
Results
[
{
"make":"MBIKE",
"description":"27.5 inch electric mountain bike",
"accessories":[
{
"category":"tyres",
"brand":"hutchinson",
"type":"Kraken 29x"
},
{
"category":"seat",
"brand":"ergon",
"type":"SR road sport gel"
},
{
"category":"derailleur",
"brand":"shimano",
"type":"ultegra D12"
}
]
},
{
"make":"EBIKE",
"description":"Electric hybrid bike",
"accessories":[
{
"category":"tyres",
"brand":"vittoria",
"type":"Gravel terrend mix"
},
{
"category":"seat",
"brand":"selle italia",
"type":"SMTB black L3"
},
{
"category":"derailleur",
"brand":"sram",
"type":"GX 10"
}
]
},
{
"make":"WBIKE",
"description":"Women's road bike",
"accessories":[
{
"category":"tyres",
"brand":"michelin",
"type":"power cup flex"
},
{
"category":"seat",
"brand":"xlc",
"type":"geltech ergo"
},
{
"category":"derailleur",
"brand":"ceramicspeed",
"type":"Eagle EAX"
}
]
}
]
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 bikesaccessories
SELECT {
make = make,
description = description,
accessories = (
SELECT {
category = 'tyres',
brand = tyres.brand,
type = tyres.type
}
UNION ALL
SELECT {
category = 'seat',
brand = seat.brand,
type = seat.type
}
UNION ALL
FROM 1 TO 1
SELECT {
category = 'derailleur',
brand = derailleur.brand,
type = derailleur.type
}
)
}