Skip to content

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, and enum.

Syntax

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

setEqualsTo(array1: array<T>, array2: array<T>): bool
(array1: array<T>).setEqualsTo(array2: array<T>): bool

Arguments

NameTypeRequiredDescription
array1arraytrueThe first array to compare
array2arraytrueThe 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.

create arrays_equal from setEqualsTo(array_1, array_2)
create arrays_equal from array_1.setEqualsTo(array_2)

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
}