Scenario: Joining two files based on an exact match and saving the result to a local file - 6.3

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

This scenario describes a four-component Job that combines data of an input file and a reference file that matches a given join key, removes unwanted columns, and then saves the final result to a local file.

The main input file contains the information about people's IDs, first names, last names, group IDs, and salaries, as shown below:

1;Woodrow;Johnson;3;1013.39
2;Millard;Monroe;2;8077.59
3;Calvin;Eisenhower;3;6866.88
4;Lyndon;Wilson;3;5726.28
5;Ronald;Garfield;2;4158.58
6;Rutherford;Buchanan;3;2897.00
7;Calvin;Coolidge;1;6650.66
8;Ulysses;Roosevelt;2;7854.78
9;Grover;Tyler;1;5226.88
10;Bill;Tyler;2;8964.66

The reference file contains only the information of group IDs and group names:

1;group_A
2;group_B

Dropping and linking the components

  1. Drop the following components from the Palette to the design workspace: tPigLoad, tPigJoin, tPigFilterColumns, and tPigStoreResult.

  2. Connect these components in a series using Row > Pig Combine connections.

Configuring the components

Loading the main input file

  1. Double-click tPigLoad to open its Basic settings view.

  2. Click the [...] button next to Edit schema to open the [Schema] dialog box.

  3. Click the [+] button to add columns, name them and define the column types according to the structure of the input file. In this example, the input schema has five columns: id (integer), firstName (string), lastName (string), groupId (integer), and salary (double).

    Then click OK to validate the setting and close the dialog box.

  4. Click Local in the Mode area.

  5. Select PigStorage from the Load function list.

  6. Fill in the Input file URI field with the full path to the input file, and leave the rest of the setting as they are.

Loading the reference file and setting up an inner join

  1. Double-click tPigJoin to open its Basic settings view.

  2. Click the [...] for the main schema to open the [Schema] dialog box.

  3. Check that input schema is correctly retrieved from the preceding component. If needed, click the [->>] button to copy all the columns of the input schema to the output schema.

  4. Click the [+] button under the output panel to add new columns according to the data structure of the reference file, groupId_ref (integer) and groupName (string) in this example. Then click OK to close the dialog box.

  5. Click the [...] for the schema lookup flow to open the [Schema] dialog box.

  6. Click the [+] button under the output panel to add two columns: groupId_ref (integer) and groupName (string), and then click OK to close the dialog box.

  7. In the Filename field, specify the full path to the reference file.

  8. Click the [+] button under the Join key table to add a new line, and select groupId and groupId_ref respectively from the Input and Lookup lists to match data from the main input flow with data from the lookup flow based on the group ID.

  9. From the Join Mode list, select inner-join.

Defining the final output schema and the output file

  1. Double-click tPigFilterColumns to open its Basic settings view.

  2. Click the [...] button next to Edit schema to open the [Schema] dialog box.

  3. From the input schema, select the columns you want to include in your result file by clicking them one after another while pressing the Shift key, and click the [->] button to copy them to the output schema. Then, click OK to validate the schema setting and close the dialog box.

    In this example, we want the result file to include all the information except the group IDs.

  4. Double-click tPigStoreResult to open its Basic settings view.

  5. Click Sync columns to retrieve the schema structure from the preceding component.

  6. Fill in the Result file field with the full path to the result file, and select the Remove result file directory if exists check box.

  7. Select PigStorage from the Store function list, and leave rest of the settings as they are.

Saving and executing the Job

  1. Press Ctrl+S to save your Job.

  2. Press F6 or click Run on the Run tab to run the Job.

    The result file includes all the information related to people of group A and group B, except their group IDs.