Dérouler une boucle dans une map DSQL
Mappez plusieurs éléments non répétables au même élément de boucle.
Avant de commencer
- Vous avez créé des structures d'entrée et de sortie. Vous pouvez utiliser les échantillons JSON ci-dessous pour créer vos structures.
Pourquoi et quand exécuter cette tâche
[
{
"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"
}
}
]
La structure de sortie ressemble à ceci :
[
{
"make": "",
"description": "",
"accessories": [
{
"category": "",
"brand": "",
"type": ""
}
]
}
]
Procédure
Résultats
[
{
"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"
}
]
}
]
Vous pouvez également consulter la vue DSQL Script (Script DSQL) pour voir comment cela est géré avec Data Shaping Query Language et l'utilisation de la clause UNION ALL. Pour plus d'informations, consultez le Guide de référence de Talend Data Shaping Language. Dans cet exemple, le script suivant est généré :
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
}
)
}