Skip to content

setDiffSymmetric

Description

Returns the symmetric difference of two arrays, producing a new array with elements that exist in either array1 or array2 but not in both.

  • Duplicates are discarded when computing the difference.
  • Supported element types include string, bool, number, interval, timestamp, regexp, and enum.

Syntax

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

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

Arguments

NameTypeRequiredDescription
array1arraytrueThe first array to compare
array2arraytrueThe second array to compare

Example

Use case: Identify differences between two IP allow lists

Suppose you maintain two separate allow lists of IP addresses. Consider the following input:

{
    "ip_addresses_a": ["156.76.87.4", "156.76.12.4", "156.74.1.4"],
    "ip_addresses_b": ["156.76.87.4", "156.76.1.4"]
}

By applying setDiffSymmetric, you can find IPs that exist in one list but not the other.

create diff_ips from setDiffSymmetric(ip_addresses_a, ip_addresses_b)
create diff_ips from ip_addresses_a.setDiffSymmetric(ip_addresses_b)

Output

The result will include a new field diff_ips showing only the differing elements:

{
    "ip_addresses_a": ["156.76.87.4", "156.76.12.4", "156.74.1.4"],
    "ip_addresses_b": ["156.76.87.4", "156.76.1.4"],
    "diff_ips": ["156.76.12.4", "156.74.1.4", "156.76.1.4"]
}