Limit Logic Documentation
Purpose
The "limit" logic in the Vantage analytics and data platform is designed to restrict the quantity of output data in a functional data processing flow. It receives a dataset, processes it according to defined parameters, and returns a truncated version of that dataset based on predefined limits. This is especially useful in scenarios where only a subset of data is needed for analysis, visualization, or other logical operations.
Settings
The "limit" logic contains the following configurable settings:
1. Count
- Input Type: Numeric
- Description: The
countsetting defines the maximum number of items to return from the dataset. It is expected to be a non-negative integer. If the count is set too high (greater than the available items), the logic will simply return the entire dataset up to that count. - Default Value: No default value; must be explicitly set. If
countis not provided or is negative, an error is thrown.
2. Max
- Input Type: Numeric (Optional)
- Description: The
maxsetting serves as an upper limit on the number of items that can be returned. If this value is greater thancount, the actual number of items returned will be limited tocount. Ifmaxis not provided, the function will default to usingcountalone, potentially allowing more items than intended to be returned ifcountis higher than the actual dataset length. - Default Value: No default value; if not set or is less than or equal to zero, it is ignored.
How It Works
Upon invocation, the createLimitNode function evaluates the incoming parameters for count and max, ensuring that they meet the required criteria. Specifically, it checks for the type and value of count to ensure that it is a non-negative number, raising an error if it does not meet the criteria.
The function calculates the effective cap for data truncation using the maximum of the provided values. If max is positive and less than count, the cap is set to max. If max is not provided or invalid, it defaults to count. The logic then processes a given array of data, returning a sliced version based on the calculated cap.
Upon execution, if the provided data is not an array, an empty array is returned.
Expected Data
The "limit" logic expects the following type of data:
- Data Type: Array
- Description: The input should be a valid array of objects or any kind of array data. It processes this data based on the defined limits set by
countandmax.
Use Cases & Examples
Use Case 1: Data Visualization
In a dashboard application, you may want to display the top 10 sales records from a dataset of thousands. The "limit" logic enables truncating the dataset to ensure viewers can see only pertinent information without overwhelming them.
Use Case 2: API Data Pagination
When fetching data from an API, you can implement the "limit" logic to limit the results returned to users. For example, returning a maximum of 50 results at a time enhances performance and usability.
Use Case 3: Data Sampling for Analytics
In a data processing pipeline, you may wish to analyze a sample of data rather than the full dataset to save on computational resources. The "limit" logic allows you to define a fixed number of records you want to work with.
Example Configuration
To implement the "limit" logic in a data processing scenario where we want to return only the top 5 records from a dataset of sales transactions:
const limitNode = createLimitNode({
count: 5,
max: 10 // This parameter can be included but will not affect the output since count is lower.
});
// Sample input data
const salesData = [
{ transactionId: 1, amount: 100 },
{ transactionId: 2, amount: 150 },
{ transactionId: 3, amount: 200 },
{ transactionId: 4, amount: 50 },
{ transactionId: 5, amount: 300 },
{ transactionId: 6, amount: 400 },
];
// Execute logic
const result = limitNode.execute(salesData);
console.log(result);In this case, result would return the first 5 records from the salesData array, adhering to the constraints set by the count value. If max were specified and less than count, it would adjust accordingly, but given the current example, max does not alter the outcome.