Articles in this section

Sort and group records

Sorting and grouping shape the records an export or lookup hands to the next step: sorting puts them in order by one or more fields, and grouping collects records that share a value into one record that holds them all — every line of one order as a single record, say, so a later import can create the order and its lines together. Which of the two you can use depends on where the records come from. This article explains that, walks through setting sort and group fields, and describes how grouped records behave.

Step Can sort Can group
Export or lookup that reads files — from FTP, Amazon S3, or Data loader, for example Yes Yes
Export or lookup that reads an HTTP API, a database, or a data warehouse No — the application decides the order Yes

Sort and group the records

  1. Go to Build build-icon.png > Flows, open the flow, and then select the export or lookup step to open its editor.
  2. For a file export, turn on File has header if the first row holds column names, so the columns can be sorted and grouped by name.
  3. Expand How would you like to group and sort records? (on an API or database export, Would you like to group records?).
  4. For a file export, in Sort records by fields add each Field in the order you want the sorts applied, and set its Order to ascending or descending. Enter a field by its ID, or use dot notation for a nested field.
  5. In Group records by fields, enter the fields to group by. Records with the same values in these fields become one record. Only fields with a basic data type — strings and numbers — can be grouped.
  6. Select Save & close.

Sorting doesn't order numeric fields or dates by value; it compares them as text.

How grouping works

  • Records are grouped in the order the group fields are entered, from top to bottom.
  • A record that's missing a group field is placed in its own "missing fields" group.
  • If you sort and group, records are sorted first and then grouped. If you only group, records are grouped in the order the application returned them, so grouping may split what should be one group when the application doesn't sort its output.
  • A group has to fit in one page. Page size (in Advanced) sets how many records or groups a page holds; a single group larger than the page is dropped from the export and reported as an error. See Create an export.
  • Grouping changes which field integrator.io uses as a record's default trace key, and a trace key override set on a grouped export doesn't reach the errors on the next step. See Set a custom trace key to uniquely identify a record.

Example

Four records, each with a CATEGORY field:

{
  "page_of_records": [
    { "record": { "NAME": "Sarah", "AGE": 97,  "PURCHASE": "Beach towel", "CATEGORY": "Summer" } },
    { "record": { "NAME": "John",  "AGE": 98,  "PURCHASE": "Ski gloves",  "CATEGORY": "Winter" } },
    { "record": { "NAME": "Ana",   "AGE": 99,  "PURCHASE": "Beach ball",  "CATEGORY": "Summer" } },
    { "record": { "NAME": "James", "AGE": 100, "PURCHASE": "Snowboard",   "CATEGORY": "Winter" } }
  ]
}

Grouped by CATEGORY, the page holds two records, each with a rows array:

{
  "page_of_records": [
    { "rows": [
        { "CATEGORY": "Summer", "NAME": "Sarah", "AGE": 97, "PURCHASE": "Beach towel" },
        { "CATEGORY": "Summer", "NAME": "Ana",   "AGE": 99, "PURCHASE": "Beach ball" }
    ] },
    { "rows": [
        { "CATEGORY": "Winter", "NAME": "John",  "AGE": 98,  "PURCHASE": "Ski gloves" },
        { "CATEGORY": "Winter", "NAME": "James", "AGE": 100, "PURCHASE": "Snowboard" }
    ] }
  ]
}

A CSV file works the same way: each row is a record, and grouping by the Category column produces one record per category with the matching rows inside it. To group by more than one field — CATEGORY then PURCHASE, for example — enter the fields in that order.

Existing flows and deprecated grouping fields

Exports and lookups built before the current Sort and group settings existed may still use the earlier grouping fields. They keep working until you open the step and use the current settings:

  • The earlier fields stay available in the editor until you enter a value in the current settings.
  • When you do, integrator.io generates the equivalent current group fields from the earlier ones. Check them — they may need adjusting.
  • After you save, the earlier fields are removed from the editor. They can still be set through the integrator.io API, but not in the UI, and they aren't offered on new steps.