setEqualsTo
Description
Returns true if array1 and array2 contain the same unique elements, or false otherwise.
- When comparing arrays, duplicates are discarded. This means two arrays of different lengths but with the same unique elements are considered equal.
- Supported element types include
string,bool,number,interval,timestamp,regexp, andenum.
Syntax
Like many functions in DataPrime, setEqualsTo supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
setEqualsTo(array1: array<T>, array2: array<T>): bool
(array1: array<T>).setEqualsTo(array2: array<T>): bool
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
array1 | array<T> | true | The first array to compare |
array2 | array<T> | true | The second array to compare |
Example
Use case: Compare arrays for unique element equality
Suppose you have two arrays that may contain duplicate elements. Consider the following input:
{
"array_1": ["val1", "val1", "val2", "val2", "val3"],
"array_2": ["val1", "val2", "val3", "val3", "val3"]
}
By applying setEqualsTo, you can determine if both arrays contain the same set of unique values, regardless of duplicates.
Example query
- Function notation
- Method notation
create arrays_equal from setEqualsTo(array_1, array_2)
create arrays_equal from array_1.setEqualsTo(array_2)
Example output
The result will include a new field arrays_equal indicating whether the sets are equal:
{
"array_1": ["val1", "val1", "val2", "val2", "val3"],
"array_2": ["val1", "val2", "val3", "val3", "val3"],
"arrays_equal": true
}