Skip to content

setUnion - Returns the union of two arrays

setUnion will return the union of both arrays, when treated as sets.

Note

Both arrays are treated as Sets which means

  • Duplicates are removed from both arrays
  • Order is not preserved in the resulting array
  • null is treated as an empty set.

Syntax

Like many functions in DataPrime, setUnion supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

setUnion(array1: array<T>, array2: array<T>): array<T>
array1: array<T>.setUnion(array2: array<T>): array<T>

Arguments

NameTypeRequiredDescription
array1array of type TtrueT must be either string, bool, number, interval, timestamp, regexp or enum
array2array of type TtrueT must be either string, bool, number, interval, timestamp, regexp or enum

Example - Seeing unique jobs in flight

{
    "processing_jobs_waiting": ["job1", "job2", "job3"],
    "loading_jobs_waiting": ["job1", "job2", "job3"]
}

If we want to see all processing and loading jobs in one place, we could use arrayConcat but this will result in duplicates. For our use case, we only want to see each unique job, which means we can use setUnion:

create all_jobs from setUnion(processing_jobs_waiting, loading_jobs_waiting)
create all_jobs from processing_jobs_waiting.setUnion(loading_jobs_waiting)

This will result in the following document:

{
    "processing_jobs_waiting": ["job1", "job2", "job3"],
    "loading_jobs_waiting": ["job1", "job2", "job3"],
    "all_jobs": ["job1", "job2", "job3"]
}