Talend Sort Row Data

The Talend Sort row or tSortRow field use to sort the input records in ascending or descending order and returns the output. We can use this Talend Sort Row field to see the sales in high to low, etc.

In this Talend Sort row example, we used the Customer table in our SQL Server database. The following image shows the data inside that table.

Talend Sort Data 1

Talend Sort Row Example

If you select the tSortRow in the palette, you can see a little tooltip explaining the field. The Talend tSortRow sort the data flows. It allows advanced sorting options such as multi-column sorting, ascending, descending sorting, alphabetical sorting.

Talend Sort Data 2

First, drag and drop the DBConnection and DBCommit to establish a connection to the SQL Server, and to close it. Second, use the DBInput, and choose the existing Connection option and select the tDBConnection. Next, select the schema from the Talend Repository because all our table schemas are available in Repository.

Talend Sort Data 3

Next, click on the browse button, and select the Customers table from the Table Schemas Metadata.

Talend Sort Data 4

Now, you can see the Customer table as the Table Name. Next, click the Guess Query button so that Talend will automatically write a Select Statement query for you.

Talend Sort Data 5

Next, drag and drop the Talend tSortRow from palette to job design.

Talend Sort Data 6

Please connect the DBInput main row to Talend tSortRow. Mostly, the input columns will sync with tSortRow. If that is not the case, then click on the Sync columns button.

Talend Sort Data 7

Next, click the Edit Schema button to check or alter the tSortRow schema as you need.

Talend Sort Data 8

Within the Talend Sort Row Component tab, there is the Criteria section. It is a place where we select the column and specify the sorting order.

Please click on the Add (plus) button. By default, it adds the first column, i.e., EmpID from the Customers table.

Talend Sort Data 9

Please use the drop-down box to select the required column. Here, we chose the Occupation field.

Talend Sort Data 10

Under the sort num or alpha, we have the following options:

  • num: Use this for sorting numeric values or numbers.
  • alpha: To sort the string data or alphabets.
  • date: Use this sorting option for sorting date values.
Talend Sort Data 11

Since Occupation has string data, we selected the alpha. Next, we can keep the order asc or desc option, and by default, asc. Otherwise, you can choose the desc.

Talend Sort Data 12

Next, we are using the DBOutput to save the Talend tSortRow output in a SQL Database. Here, we are creating the Talend_Sorted_Customers table as the destination table.

Talend Sort Data 13

Let us run the Talend Sort Row Job.

Talend Sort Data 14

From the above screenshot, you can see an error stating that EmpID is an identity column. But we are inserting records into it. To resolve this, please go to the components tab.

Please check the Turn on Identity Insert option and Specify the identity field option. Next, select the Identity field and specify the start value and Step. By default, it will choose the integer field and assigns one as Start value and Step. However, you can change as per your requirements.

Talend Sort Data 16

Now, you can see that the Talend sort row data job has run successfully!

Talend Sort Data 17

Let me open the Management studio to check the Talend Sort row result. Remember, Talend tSortRow is the same as the SQL Order By Clause.

Talend Sort Data 18

This time, we are using two fields and run the job. It means Talend tSortRow has to sort the Customers by Occupation in ascending order and then sort by Yearly Income in descending order.

Talend Sort Data 19

Please check the Talend Sort row job result.

Talend Sort Data 20

Here, we used another column HireDate to sort the date field in descending order.

Talend Sort Data 21

Please check the Talend tSortRow result.

Talend Sort Data 22