DSQLマップでループを展開
複数の非ルーピングエレメントを同じルーピングエレメントにマッピングします。
始める前に
- 入力と出力のストラクチャーが作成済みであること。ストラクチャーの作成には下のJSONサンプルを使用できます。
このタスクについて
[
{
"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"
}
}
]
出力ストラクチャーは次のようになります。
[
{
"make": "",
"description": "",
"accessories": [
{
"category": "",
"brand": "",
"type": ""
}
]
}
]
手順
タスクの結果
[
{
"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"
}
]
}
]
また、[DSQL Script] (DSQL スクリプト)ビューで、UNION ALL句を使ったData Shaping Query Languageでどのように処理されるかを確認することもできます。詳細は、TalendData Shaping Languageリファレンスガイドをご覧ください。この例では、次のスクリプトが生成されます。
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
}
)
}