setUnion
Description
Returns the union of two arrays, producing a new array that contains all unique elements from both.
Both arrays are treated as sets:
Duplicates are removed
- Order is not preserved in the result
null
is treated as an empty set- Supported element types include
string
,bool
,number
,interval
,timestamp
,regexp
, andenum
.
Syntax
Like many functions in DataPrime, setUnion
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
array1 | array | true | The first array to combine |
array2 | array | true | The second array to combine |
Example
Use case: Combine processing and loading jobs into a unique set
Suppose you have arrays of processing and loading jobs. Consider the following input:
{
"processing_jobs_waiting": ["job1", "job2", "job3", "job4"],
"loading_jobs_waiting": ["job1", "job2", "job3"]
}
By applying setUnion
, you can merge the two arrays and keep only unique jobs.
Output
The result will include a new field all_jobs
containing unique values from both arrays:
{
"processing_jobs_waiting": ["job1", "job2", "job3"],
"loading_jobs_waiting": ["job1", "job2", "job3"],
"all_jobs": ["job1", "job2", "job3", "job4"]
}
Theme
Light