Sort Logic Documentation
Overview
The Sort Logic in the Vantage platform is designed to enable users to sort datasets based on specified fields in either ascending or descending order. This functionality is vital for data analysis, allowing users to organize their data efficiently before processing, visualizing, or drawing insights from it.
Purpose
The primary purpose of the Sort Logic is to rearrange elements in an array based on a specified criterion. It provides flexibility through various sorting methods, including standard sorting, custom orders, and user-defined comparators, making it versatile for multiple data scenarios.
Settings
1. Field
- Input Type: String
- Description: This setting specifies the attribute or key of the data elements that will be used for sorting. Changing this setting will alter the field on which the sort is performed.
- Default Value:
undefined
2. Direction
- Input Type: String (options: 'ASC', 'DESC')
- Description: This setting determines the order of the sort. 'ASC' sorts the data in ascending order, while 'DESC' sorts it in descending order. Changing this affects the sort order of the resulting dataset.
- Default Value: 'ASC'
3. CustomOrder
- Input Type: Array
- Description: This setting allows users to define a custom order for sorting that overrides the standard sorting logic. The elements in the input array dictate the rank of the attributes in the field for sorting. Changing this array will reorder the resultant array according to the specified sequence.
- Default Value:
undefined
4. Comparator
- Input Type: Function
- Description: This setting allows users to provide a custom comparator function for sorting. If this function is defined, it will take precedence over other sorting methods. The comparator function accepts two arguments and must return a negative number, zero, or a positive number to indicate the order of the elements. Changing this can result in entirely different sorting behavior based on the logic defined in the comparator function.
- Default Value:
undefined
How It Works
Upon invoking the createSortNode function, the Sort Logic performs the following operations:
- Input Validation: First, it checks if the input data is an array. If not, it returns an empty array.
- Custom Comparator: If a custom comparator function is provided, it uses that function to sort the data.
- Custom Order: If a custom order array is provided, it maps the defined order to the data based on the specified field.
- Standard Sorting: If no custom sort options are defined, it performs a standard sort based on the defined field and direction.
The result is a new sorted array without modifying the original dataset, adhering to the immutability principles.
Data Expectations
The Sort Logic expects the following structure for the input data:
- The input should be an array of objects where each object contains the fields that match the specified
fieldsetting. If any objects do not contain the specified field, they will be sorted according to the rules defined in the sorting logic, potentially at the end of the sorted result if the field does not exist.
AI Integrations
Currently, there are no direct AI integrations associated with the Sort Logic. However, it can be a part of larger processes where machine learning predictions can be sorted as part of data preprocessing steps before analysis.
Billing Impacts
Using the Sort Logic is subject to the platform's pricing structure. Sorting operations may count towards data processing units based on the size of the dataset being sorted and the complexity of the operations (e.g., using custom comparators). Users should monitor their usage and understand how these operations contribute to their overall billing.
Use Cases & Examples
Use Case 1: Data Preparation for Reporting
Sorting customer sales data by date in ascending order to prepare a time-series report.
Use Case 2: Product Listing Optimization
Sorting a list of products based on user ratings to display top-rated products first.
Use Case 3: Ranking Employees
Sorting employee records based on performance score to present the best-performing employees in a quarterly review.
Detailed Example: Sorting Customer Sales Data
Use Case: Preparing a Report for Analysis
Configuration:
const sortNode = createSortNode({
field: 'purchaseDate',
direction: 'ASC',
customOrder: undefined,
comparator: undefined
});Input Data:
[
{ "customerId": 1, "purchaseDate": "2023-10-05", "amount": 250 },
{ "customerId": 2, "purchaseDate": "2023-09-15", "amount": 450 },
{ "customerId": 3, "purchaseDate": null, "amount": 300 },
{ "customerId": 4, "purchaseDate": "2023-09-20", "amount": 150 }
]Output from Sorting:
[
{ "customerId": 2, "purchaseDate": "2023-09-15", "amount": 450 },
{ "customerId": 4, "purchaseDate": "2023-09-20", "amount": 150 },
{ "customerId": 1, "purchaseDate": "2023-10-05", "amount": 250 },
{ "customerId": 3, "purchaseDate": null, "amount": 300 }
]In this example, the input data is sorted by purchaseDate in ascending order, allowing a time-sequenced view of sales activity.