In this scenario we will sort entries in an input file based on a dynamic schema, display the sorting result on the Run console, and save the sorting result in an output file. For more information about the dynamic schema feature, see Talend Studio User Guide.
Drop the components required for this use case: tFileInputDelimited, tSortRow, 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, the input file cars.csv has five columns: ID_Owner, Registration, Make, Color, and ID_Reseller.
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 ID_Owner 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 propagate the schema and close the schema editor.
Double-click tSortRow to display the Basic settings view.
Add a row in the Criteria table by clicking the plus button, select Other under Schema column, select alpha as the sorting type, and select the ascending or descending order for data output.
Dynamic column sorting works only when the sorting type is set to alpha.
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 sorted data.
Save your Job and press F6 to run it.
The sorting result is displayed on the Run console and written into the output file.