この接続学習パスでは、XMLファイルをCSVに変換する方法を説明するチェーンを作成します。また、データセットをどのように比較し、差異を分離するかを探求する。
| プライマリ学習目標 | XMLコネクター |
| セカンダリ学習目標 | 表形式トランスフォーメーション、スマートフィルター、区切り文字の変更、高度なクエリコマンド |
| 前提条件 | XML コネクタ接続の構成 |
| サポートテンプレート | CLP|XMLデータを使用する |
ステップ1:チェーンの作成
- Add a new Chain, and name the Chain: CLP | Accessing XML Data.
- 次のように 2 つのチェーン変数を作成します:
- Under Chain Variables, click the plus sign (+) twice.
- 変数には以下の名称と値を使用します:
- XML変数
- Name: cv-XML-Employee
- Value: https://cs-sftp-training-bucket.s3.amazonaws.com/cs-training/transformation-qs/employees.xml
- CSV 変数
- Name: cv-CSV-Employee
- Value: https://cs-sftp-training-bucket.s3.amazonaws.com/cs-training/transformation-qs/employee_detail.csv
- XML変数
- チェーンを保存します。
ステップ2:CSV書式設定でのデータ取得
HTTPコネクターを使用して、CSV書式で人数関連データを取得します。後のステップでは、同様の人数情報をXML書式設定で取得し、データセットを比較して相違点を特定する。
- Add a GET Command from the HTTP Connector to the Start node.
-
以下の値を使用してコマンドを構成します:
名前 GET - CSV書式での人員数 ユーザー名称 <leave blank> パスワード <leave blank> CA証明書 <leave blank> 証明書 <leave blank> 証明書秘密キー <leave blank> 表示レスポンス チェック済み URL cv-CSV-Employee Chain Variable クエリ文字列 <leave blank> コンテンツタイプ テキスト/CSV 応答 <leave blank> - コマンドを保存する。
ステップ3:XML書式でのデータ取得
HTTPコネクターを使用して、XML書式設定で人数関連データを取得します。ステップ2でメモしたように、次のステップでは、XMLデータセットとCSVデータセットを比較し、相違点を特定する。
- Add a GET Command from the HTTP Connector to the Chain.
- Connect the Start Node (GET - Headcount in CSV Format) to the GET Command.
-
以下の値を使用してコマンドを構成します:
名前 GET - XML書式設定で人数 ユーザー名称 <leave blank> パスワード <leave blank> CA証明書 <leave blank> 証明書 <leave blank> 証明書秘密キー <leave blank> 表示レスポンス チェック済み URL cv-XML-Employee Chain Variable クエリ文字列 <leave blank> コンテンツタイプ application/xml 応答 <leave blank> - コマンドを保存する。
ステップ4:XMLファイルを区切り文字に変換する
XML コネクターを使用して、XML データを CSV 形式に変換し、区切り書式でのデータを期待するチェーンの後のコマンドを利用できるようにする。
- Add an Element List to CSV Command from the XML Connector to the Chain.
- Connect the GET - Headcount in XML Format Command to the Element List to CSV Command.
- 以下の値を使用してコマンドを構成します:
- For the Input File parameter, select the Response Output from the GET - Headcount in XML Format Command.
- Leave the Input Text parameter blank.
- For the Path to root parameter, enter the following envelope information:
/employee_data/employee - Mark the Preview Result parameter checkbox.
-
For the Columns section, click the Add button 12 times.
For each of the added columns, enter the name of the field from the data record previewed in the previous step in both the Column Name and XPath fields.
Example: emp_id⚠️ XPathフィールドは大文字と小文字を区別し、エンベロープの大文字と小文字を一致させなければならない。
- 複数値デリミタ・パラメータには、パイプ (|) を入力します。
- コマンドを保存する。
- チェーンを更新、実施、実行します。
-
Review the Log tab of the Element List to CSV - All Employees Command node and confirm a list of employees is displayed.
⚠️ このステップの実行と結果のレビューは省略しないでください。このコマンドのコピーがチェーンに作成され、その後、コマンドの複数のインスタンスにわたってエラーを修正する必要があるからです。
ステップ5:変換後のXMLをタブ区切りからカンマ区切りに変更する
Tabular Transformation Connector を使用して、XML 変換から生成された出力をタブ区切り書式からカンマ区切り書式に変換します。
- Add a Change Delimiter Command from the Tabular Transformation Connector to the Chain.
- Connect the Element List to CSV - All Employees Command to the Change Delimiter Command.
- 以下の値を使用してコマンドを構成します:
- Name: Change Delimiter - All Employees
- Input File: Converted File Output from the Element List to CSV - All Employees Command
- Input Delimiter: \t
- Output Delimiter: , (comma)
- コマンドを保存する。
ステップ6:CSVとXMLのデータセットを比較し、相違点を特定する。
Use Advanced Query to systematically identify differences between the XML and native CSV data sets. この例では、XMLデータセットの中でCSVデータセットと異なるレコードや欠落しているレコードを識別します。CSVデータセット内で検出された追加レコードで、XMLデータセットにないものは、この演習では識別されません。
- Add an Advanced Query Command from the Tabular Transformation Connector to the Chain.
- Connect the Change Delimiter - All Employees Command to the Advanced Query Command.
- Name the Command: Advanced Query - All Employees.
- In the Tables section, click the Add button to add a second tab.
- 最初のテーブル向けに:
- Specify the CSV Result Output from the Change Delimiter - All Employees Command.
- Specify XML as the Table Name.
- 2つ目のテーブル:
- Specify the Response Output from the GET - Headcount in CSV Format Command.
Specify CSV as the Table Name. - In the Query parameter, enter the following:
Select * from XML EXCEPT Select * from CSV - In the Input Delimiter and Output Delimiter fields, specify Comma.
- Check the Preview Results option.
- Specify the Response Output from the GET - Headcount in CSV Format Command.
- 最初のテーブル向けに:
- コマンドを保存する。
- Publish, Execute, and Run the Chain.
-
Review the Log tab of the Advanced Query - All Employees Command node and confirm the employee IDs match the below for the records returned by the query.
社員ID 01-6875791 10-4199621 38-3932553 63-0417180 78-3600453 85-6818050 97-2828467
ステップ7:コマンドグループの追加
コマンドグループをチェーンに追加し、コマンド整理を改善します。このステップはこの練習においては必要ですが、チェーンの技術的要件ではありません。このステップは、単にチェーンのノードを組織化する機能を説明するためのものである。
- Add a Command Group to the Chain.
- Connect the GET - Headcount in XML Format Command to the In section of the Command Group.
- Click the Command Group and then select the dropper icon to change the Command color to red.
- Name the Group: Active Employees.
ステップ8: CSVデータを現役社員のみに絞込みます。
スマートフィルターを使用して、従業員がアクティブである従業員レコードのみを保持します。フィルターを定義する際、terminated(絞込み)フィールドが空白であることは、従業員がアクティブであることを示すと仮定します。
- Add a Smart Filter Rows Command from the Tabular Transformation Connector to the Chain.
- Connect the Group Start from the Command Group to the Smart Filter Command.
- 以下の値を使用してコマンドを構成します:
- Name the Command: Smart Filter Rows - CSV Data - Active Employees.
- For the Input file parameter, select the Response Output from the GET - Headcount in CSV Format Command.
- Leave the Output file parameter blank.
- Specify Comma as the Delimiter.
- In the Filters section complete the following steps:
- Click the Add button on the Text filters.
- In the Column name parameter, enter termed.
- Check the Case Insensitive option.
- From the Condition dropdown, select Equals.
- In the Compare Text parameter, enter true.
- Check the Not option.
- Leave the Trim checkbox unchecked.
This filter will now identify any record where the field "termed" does not contain a value of true (that is, it contains "false" or is blank).
- Leave the Preview Result option marked.
- The Inverse option allows the Smart Filter to either keep (checked) or remove (unchecked) all rows that match the filter criteria. この演習では、"termed" フィールドの値が true または空白の行をすべて保持します。
To achieve this, mark (check) the Inverse checkbox. - コマンドを保存する。
ステップ8: CSVデータを現役社員のみに絞込みます。
スマートフィルターを使用して、従業員がアクティブである従業員レコードのみを保持します。フィルタを定義する際、terminated (「termed」) フィールドが空白であることは、従業員がアクティブであることを示すものとします。
- Add a Smart Filter Rows Command from the Tabular Transformation Connector to the Chain.
- Connect the Group Start from the Command Group to the Smart Filter Command.
- 以下の値を使用してコマンドを構成します:
- Name the Command: Smart Filter Rows - CSV Data - Active Employees.
- For Input file, select the Response Output from the GET - Headcount in CSV Format Command.
- Leave the Output file parameter blank.
- Specify Comma as the Delimiter.
- In the Filters section,
- Click the Add button on the Text filters.
- In the Column name parameter, enter termed.
- Check the Case Insensitive option.
- From the Condition dropdown, select Equals.
- In the Compare Text parameter, enter true.
- Check the Not option.
- Leave the Trim checkbox unchecked.
This filter will now identify any record where the field "termed" does not contain a value of true (that is, it contains "false" or is blank).
- Leave the Preview Result checkbox marked (checked).
- The Inverse option allows the Smart Filter to either keep (checked) or remove (unchecked) all rows that match the filter criteria. この演習では、用語フィールドの値がtrueまたは空白である行をすべて保持したい。To achieve this, mark (check) the Inverse checkbox.
- コマンドを保存する。
ステップ9:XMLデータをフィルターにかけながら区切り変換する
このステップでは、区切り書式に変換しながらXMLデータにフィルターをかけ、アクティブな従業員のみを識別する。このデータセットをその後、フィルター込みCSVデータセットと比較し、相違点を特定します。
- Copy the Element List to CSV - All Employees Command.
- Connect the Group Start from the Command Group to the Element List to CSV - All Employees (Copy) Command.
- Edit the Command, naming it: Element List to CSV - Active Employees.
- In the "Path to root" parameter, enter the following.
/employee_data/employee[termed!='true']
This will now identify any record where the field "termed" does not contain a value of true (that is, it contains "false" or is blank). - コマンドを保存する。
ステップ10:フィルター込みXMLデータをカンマ区切りに変更する
全従業員名簿と同様に、XMLからタブ区切りに変換されたフィルター付き正従業員名簿は、カンマ区切りに変換する必要があります。
- Copy the Change Delimiter - All Employees Command.
- Connect the Element List to CSV - Active Employees Command to the Element Change Delimiter - All Employees (Copy) Command.
- 以下の値を使用してコマンドを構成します。
- Name: Change Delimiter - Active Employees.
- Modify the Input file parameter to use the Converted File Output from the Element List to CSV - Active Employees Command.
- コマンドを保存する。
ステップ11:現役社員との違いをチェックする
全従業員名簿と同様に、XMLからタブ区切りに変換されたフィルター付き正従業員名簿は、カンマ区切りに変換する必要があります。
- Copy the Advanced Query - All Employees Command.
- Connect the Out of the Command Group to the Advanced Query - All Employees (Copy) Command. Advanced Query - All Employeesコマンドをグループアウトに接続すると、グループアウトのコマンドにチェーンが進行する前に、グループスタートに接続されているすべてのコマンドが終了します。
- 以下の値を使用してコマンドを構成します:
- Name: Advanced Query - Active Employees.
-
In the Tables section, modify the File parameter for both tables using the following values:
テーブル ファイル XML CSV Result Output from the Change Delimiter - Active Employees Command CSV Smart Filter Row Output from the Smart Filter Rows - Active Only, CSV Data Command
- コマンドを保存する。
ステップ12:エクササイズのテスト
チェーンが完成したら、結果をテストする。
- Publish the Chain.
- Click Execute and then select Run Chain.
- Once the Chain has completed its run, click the Advanced Query - Active Employees node.
- On the Outputs tab, confirm that 4 records were output.
-
ログタブをクリックし、クエリによって返されたレコードの従業員IDが下記と一致することを確認します。
社員 ID 01-6875791 63-0417180 78-3600453 85-6818050
To learn more about data transformation using Chains, check out the Connected Learning Paths - Transformation Introduction!