Collect List on Array Function: COLLECT_LIST_ON_ARRAY
Description
This function collects elements from the input arrays (ARRAY) into a new array and returns that new array. If the DISTINCT parameter is specified, it deduplicates the input array rows (i.e., identical arrays are collected only once), rather than deduplicating elements within the arrays.
Parameters
array: Input array (ARRAY) type data.limit: Optional parameter, integer type, specifying the maximum number of elements to collect. If not specified, all elements are collected.
Return Results
- Returns an array (
ARRAY) type, with element types matching those of the input array elements. - If the
DISTINCTparameter is specified, input array rows are deduplicated before collection; identical arrays are taken only once. - If the
limitparameter is specified, the returned array contains at mostlimitelements. - The function does not guarantee the order of elements in the result array.
NULLvalues in the input arrays do not affect the calculation of the result array.
Examples
The following examples demonstrate how to use the collect_list_on_array function to collect array elements and return a new array.
Example 1: Basic usage
Example 2: Use the limit parameter to restrict the number of returned elements
Example 3: Use DISTINCT to deduplicate input array rows
The DISTINCT keyword deduplicates entire array rows, meaning identical arrays are collected only once; it does not affect elements within the arrays.
