# Sort rows

This step sorts rows based on the fields you specify and on whether they should be sorted in ascending or descending order.

If you use multiple copies of this step in parallel, merge the sorted blocks to ensure the correct sort sequence. You can further ensure the correct sequence by adding a [Sorted Merge](https://wiki.pentaho.com/display/EAI/Sorted+Merge) step immediately after the last Sort rows step.

You can create this type of transformation locally (using **Change number of copies to start**) or in a clustered environment.

### Step name

* **Step name**: Specify the unique name of the step on the canvas. You can customize the name or leave it as the default.

### Options

The Sort rows step includes the following options.

| Option                                          | Description                                                                                                                          |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| **Sort directory**                              | Directory where temporary files can be stored, if needed. If blank, the step uses the system temporary directory.                    |
| **TMP-file prefix**                             | Prefix for temporary files.                                                                                                          |
| **Sort size (rows in memory)**                  | Number of rows to sort in memory. Default is 1000000. A larger number can improve speed, but might increase memory use.              |
| **Free memory threshold (in %)**                | If free memory drops below this threshold, the sort algorithm begins paging data to disk. This value is re-verified every 1000 rows. |
| **Compress TMP Files**                          | Select to compress temporary files.                                                                                                  |
| **Only pass unique rows? (verifies keys only)** | Select to pass only unique rows to the output stream.                                                                                |
| **Fields table**                                | Fields and sort direction. You can also specify case sensitivity.                                                                    |
| **Get Fields**                                  | Populates the fields table from the incoming stream.                                                                                 |

### Field settings

Use the following settings to refine the sort behavior for individual fields.

| Setting                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Field names**                   | Name of the field on the stream.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| **Ascending**                     | **Y** for ascending order, **N** for descending order.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| **Case sensitive compare?**       | **Y** to sort by case usage, **N** to ignore case.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| **Sort based on current locale?** | **Y** to sort based on the system locale, **N** to sort based on standard UTF-8 ordering.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| **Collator strength**             | <p>If you selected <strong>Y</strong> for <strong>Sort based on current locale?</strong>, specify an integer from <code>0</code> to <code>3</code>:</p><ul><li><strong>0</strong> (Primary): base letter differences (for example, <code>a</code> vs <code>b</code>).</li><li><strong>1</strong> (Secondary): accent differences (for example, <code>a</code> vs <code>ä</code>).</li><li><strong>2</strong> (Tertiary): case differences (for example, <code>A</code> vs <code>a</code>).</li><li><strong>3</strong> (Identical): strings must match exactly (for example, <code>\u0001</code> vs <code>\u0002</code>).</li></ul> |
| **Presorted?**                    | Select **Y** if the field is already sorted. Presorting can improve efficiency.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

### Metadata injection support

This step supports metadata injection. You can use it with [ETL metadata injection](broken://pages/WMKAfAWCLgW5Fg8fiGc) to pass metadata to your transformation at runtime.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pentaho.com/pdia-data-integration/pdi-transformation-steps-reference-overview/sort-rows-transformation-step.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
