In this scenario, a four-component Java Job uses a tAggregateRow component to read data from a CSV file, group the data, and then send the grouping result to the Run console and an output file. A dynamic schema is used in this Job. For more information about dynamic schema, see Talend Studio User Guide.
Drop the components required for this use case: tFileInputDelimited, tAggregateRow, tLogRow and tFileOutputDelimited from the Palette to the design workspace.
Connect these components together using Row > Main links.
Double-click the tFileInputDelimited component to display its Basic settings view.
The dynamic schema feature is only supported in Built-In mode and requires the input file to have a header row.
Select Built-In from the Property Type list.
Click the [...] button next to the File Name field to browse to your input file. In this use case, we use a simple CSV file that has only three columns, as shown below:
Specify the header row in Header field. In this use case the first row is the header row.
Select Built-In from the Schema list, and click Edit schema to set the input schema.
The dynamic column must be defined in the last row of the schema.
In the schema editor, add two columns and name them Task and Other respectively. Set the data type of the Other column to Dynamic to retrieve all the columns undefined in the schema.
Click OK to close the schema editor.
Double-click the tAggregateRow component to display the Basic settings view.
Click Sync columns to reuse the input schema for the output row. If needed, click Edit schema and rename the columns in the output schema. In this use case, we simply keep the schema as it is.
Add a row in the Group by table by clicking the plus button, and select Other in both Output column and Input column position fields to group the data entries by the dynamic column.
Dynamic column aggregation can be carried out only for the grouping operation.
Add a row in the Operations table by clicking the plus button, select Task in both Output column and Input column position fields, and select list in the Function field so that all the entries of the Task column are listed in the grouping result.
To view the output in the form of a table on the Run console, double-click the tLogRow component and select the Table option in the Basic settings view.
Double-click the tFileOutputDelimited component to display its Basic settings view.
Click the [...] button next to the File Name field to browse to the directory where you want to save the output file, and then enter a name for the file.
Select the Include Header check box to retrieve the column names as well as the grouped data.
Save your Job and press F6 to run it.
As shown in the Job execution result, the data entries are grouped as per Team and Status.