This scenario describes a three-component Job that uses the tSurviveFields component to merge, based on different rank values, the content of data rows in different columns and then writes the result in an output file.
In this scenario, we have already stored the input schemas of the input file in the Repository. For further information about storing schema metadata in the Repository, see Talend Studio User Guide.
The input file contains four columns: grp, gender, firstname and count. The data in the input file has problems such as duplication, first names spelled differently or wrongly and different information for the same customer.
In the Repository tree view, expand Metadata and the FileExcel node where you have stored the input schemas and then drop it onto the design workspace.
The tFileInputExcel component which contains your schema displays on the workspace.
Drop a tSurviveFields and a tFileOutputExcel component from the Palette onto the design workspace.
Link the components together using Row > Main connections.
Double-click tFileInputExcel to display its Basic settings view.
All tFileInputExcel property fields are automatically filled in. If you did not define your input schemas locally in the Repository, fill in the details manually after selecting Built-in in the Schema and Property Type fields.
Double-click tSurviveFields to display its Basic settings view and define the component properties.
Click Sync columns to retrieve the schema from the preceding component. You can click the [...] next to Edit schema to view the schema.
In the Key area, click the [+] button to add a new line, and click the field and select the name of the column you want to use to merge the data from the list.
You can select multiple columns as an aggregation set if you want to merge data based on multiple criteria. For this scenario, we want to use the grp column to merge the data.
In the Operations area, click the [+] button to add new rows. Here you can define the output columns that will hold the results of the merge operation. In this scenario, we want to merge the data in the firstname, gender and count columns.
Click in the first field of the Output column and select the first output column that will hold the merge results.
Click in the first field of the Function column and select the merge operation you want to perform.
Click in the first field of the Input Column list and select the column from which the input values are to be taken.
Click in the first field of the Rank column and select the column that will be used as a basis for the merge operation.
Repeat the same process to define the parameters for the merge operation for all the columns you want to write in the output file.
Here we want to read data from the firstname and gender input columns and write only the values with the maximum rank (row count) in firstname and gender output columns. We also want to read data from the count input column and write its maximum value in a count output column.
Double-click the tFileOutputExcel component to open its Basic settings view.
Specify the path to the target file, select the Include header check box, and leave the other settings as they are.
Save your Job and press F6 to execute it.
A progress bar displays to show the percentage of the merge operation completed. When the percentage progress bar reaches 100%, the specified data is regrouped and written in the defined output columns.
The figure below illustrates a sample of the output data after the merge operation.