This deprecated node sorts data based on the specified input fields, in either ascending or descending order.
The simplest way to sort your data is by using the Sort grid in the CompareOrderExpr property. Alternatively, for more advanced techniques, you can use the Advanced tab.
Simple sort
- Firstly, connect the Sort node to a node that has run successfully to ensure that the input data is available.
- Select the Sort node and view the Properties panel.
- In the sort grid, select a Field to sort by from the drop-down menu. You can type in the drop-down to filter the list of fields to those which contain the typed text.
- By default, your data will be sorted in ascending order (low to high). If you want to sort in descending order (high to low), click the toggle button to the right of Ascending.
- You can add multiple sort criteria by repeating the steps above. The menu button to the right of each item in the sort grid allows you to reorder the sort criteria, or delete the row. The order of the sort criteria determines which field the data will be sorted by first.
You can also use the Sort node to remove duplicate records based on the field that you are sorting on by setting the Unique property to True. If you are sorting by multiple fields, all specified fields must match for the record to be removed.
Sort grid example
Consider the following input to a Sort node:
Account_Name | Account_Number | Account_ID |
---|---|---|
John | 1 | a |
John | 1 | a |
Edward | 2 | a |
John | 3 | b |
Bob | 5 | z |
John | 5 | a |
Bob | 2 | f |
Edward | 3 | b |
Edward | 1 | c |
In the Sort grid, select the three fields to sort on, in the following order:
- Account_Name
- Account_Number
- Account_ID
Accept the default sort direction of Ascending (low to high), and run the node.
The output would display the records sorted in ascending order, as follows:
Account_Name | Account_Number | Account_ID |
---|---|---|
Bob | 2 | f |
Bob | 5 | z |
Edward | 1 | c |
Edward | 2 | a |
Edward | 3 | b |
John | 1 | a |
John | 1 | a |
John | 3 | b |
John | 5 | a |
To sort this data in descending order, click the toggle button to the right of Ascending in each of the three rows.
The output would then be:
Account_Name | Account_Number | Account_ID |
---|---|---|
John | 5 | a |
John | 3 | b |
John | 1 | a |
John | 1 | a |
Edward | 3 | b |
Edward | 2 | a |
Edward | 1 | c |
Bob | 5 | z |
Bob | 2 | f |
To remove duplicate fields, set the Unique property to True. In this case, the output would then contain only 8 records as one of the "John, 1, a" records would be removed.
Advanced configuration
If you have set your sort criteria using the basic sort grid, you can click the Advanced tab to view the underlying Script.
If you want to use the Advanced tab to set your sort criteria, type the name(s) of the input field(s) that you want to sort by. You can also select an input field by clicking the menu button.
To sort by multiple fields in ascending order, enter the field names in the order that you want to sort on, separated by a comma. For example, if you are sorting an employee list, you may want to sort it by last name and then within each last name sort by first name, as in the following example, where Last_Name
and First_Name
are the input field names:
Last_Name, First_Name
By default, the node sorts in ascending order (low to high). If you would like to sort data in descending order (high to low), use the Script reverse function, in either of the two following formats, where value
is the name of the input field that you want to sort by:
value.reverse()reverse(value)
To sort by multiple fields in descending order, use the following format where value
is the name of the input fields that you want to sort by:
reverse (list(value_1, value_2, value_3))
Given that all basic sort criteria can be configured in the Sort grid, a more likely use case for the Advanced tab is if you want to sort on a sub-string, as per the following example.
Advanced example - sorting on a sub-string
Consider the following input to a Sort node:
Input_datastring |
---|
123-456 |
456-123 |
908-034 |
Type the Script expression to sort the data in the Advanced tab of the CompareOrderExpr property. To sort based on a sub-string, you can use the substr Script function.
For example, to sort the data based on a subset of three characters, starting at the third character in from the right, you would type:
"Input_data".substr(-3, 3)
The output would then be as follows:
Input_datastring |
---|
908-034 |
456-123 |
123-456 |
Properties
CompareOrderExpr
The simplest way to sort your data is by using the Sort grid to select the fields that you want to sort by, then choosing whether to accept the default sort order of Ascending (low to high) or to change it to Descending (high to low).
If you want to use advanced techniques, such as sorting by sub-string, specify the name of the fields that you want to sort by in the Advanced tab, separating each field name with a comma. To sort in descending order, use the Script .reverse()
function.
A value is required for this property.
StableSort
Optionally specify whether, for any items that are already in order, their order is maintained.
The default value is False.
Unique
Optionally specify whether to exclude duplicate entries based on the field that you are sorting on. If you are sorting by multiple fields, all specified fields must match for the record to be removed.
The default value is False.
Epsilon
Optionally specify a tolerance epsilon for comparing floating point numbers, for example 0.1.
MergeOnly
Optionally specify whether to only perform a merge operation on the input data. This is useful for merging the output of multiple parallel sort nodes.
Note: This option requires the data on the input pins to already be sorted. Unsorted input data will produce undefined unsorted output data.
Inputs and outputs
Inputs: in1, multiple optional.
Outputs: out1.