メイン コンテンツをスキップする 補完的コンテンツへスキップ

DSQLマップでループを展開

Availability-noteBeta
複数の非ルーピングエレメントを同じルーピングエレメントにマッピングします。

始める前に

  • 入力と出力のストラクチャーが作成済みであること。ストラクチャーの作成には下のJSONサンプルを使用できます。

このタスクについて

この例では、2つの非ルーピングエレメントからデータを抽出し、出力にある1つのループにマッピングするDSQLマップを作成します。 入力データは次のようになります。
[
    {
        "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": ""
            }
        ]
    }
]

手順

  1. 新しいDSQLマップを作成して入力ストラクチャーと出力ストラクチャーを追加します。
    ルートエレメント間に最初のマッピングが自動的に作成されます。出力ストラクチャーのルートエレメントに、対応するData Shaping Query Languageの式が表示されます。
  2. 出力ストラクチャーにあるaccessoriesエレメントを右クリックし、[Unroll] (展開)をクリックしてこのステップを繰り返します。
    これにより、同一の非ルーピングエレメントが2つ作成されます。このエレメントは、入力されたtyresseatderailleurという各エレメントを同じaccessories出力ループにマッピングするために必要です。展開後、マップ内のストラクチャーに別々のaccessoriesエレメントが3つ表示されますが、出力にはその3つのエレメントのコンテンツを持つaccessories配列が1つだけ含まれるようになります。
  3. 次のエレメントをドラッグ&ドロップしてマッピングします。
    • bikesaccessories.makebikesaccessorieslist.make
    • bikesaccessories.descriptionbikesaccessorieslist.description
    • bikesaccessories.tyresを最初のbikesaccessorieslist.accessories
    • bikesaccessories.seatを2番目のbikesaccessorieslist.accessories
    • bikesaccessories.derailleurを3番目のbikesaccessorieslist.accessories
    情報メモヒント: 必要であれば、展開済みのエレメントを右クリックして[Move Up] (上に移動)[Move Down] (下に移動)[Delete] (削除)をクリックすることで、その分割エレメントを移動または削除できます。
  4. 最初のaccessoriesエレメントの下にあるcategoryエレメントをクリックし、式エディターに'tyres'と入力します。
  5. 2番目と3番目のaccessoriesエレメントについても同じ手順を繰り返し、それぞれ'seat''derailleur'と入力します。

タスクの結果

マップが設定され、[Test Run] (テスト実行)機能を使った結果をチェックできるようになります。この例では、次の結果が返されます。
[
   {
      "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
      }
   )
}

このページは役に立ちましたか?

このページまたはコンテンツに、タイポ、ステップの省略、技術的エラーなどの問題が見つかった場合は、お知らせください。改善に役立たせていただきます。