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, andenum.
Syntax
Like many functions in DataPrime, setDiffSymmetric supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
setDiffSymmetric(array1: array<T>, array2: array<T>): array<T>
(array1: array<T>).setDiffSymmetric(array2: array<T>): array<T>
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: 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.
Example query
- Function notation
- Method notation
create diff_ips from setDiffSymmetric(ip_addresses_a, ip_addresses_b)
create diff_ips from ip_addresses_a.setDiffSymmetric(ip_addresses_b)
Example 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"]
}