setIntersection
Description
Returns the intersection of two arrays, producing a new array with elements common to both.
Both arrays are treated as sets:
Duplicates are removed from both arrays
- Order is not preserved in the result
null
is treated as an empty set- Supported element types include
string
,bool
,number
,interval
,timestamp
,regexp
, andenum
.
Syntax
Like many functions in DataPrime, setIntersection
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
array1 | array | true | The first array to compare |
array2 | array | true | The second array to compare |
Example
Use case: Compare observed IPs against a block list
Suppose you collect IP addresses accessing different paths. Consider the following input:
{
"path": "/home",
"ip_addresses": ["156.76.87.4", "156.76.12.4", "156.74.1.4"]
},
{
"path": "/checkout",
"ip_addresses": ["156.76.87.4"]
}
By applying setIntersection
, you can identify which observed IP addresses also appear in a known block list.
Output
The result will include a new field unauthorized_ip_addresses
showing IPs found in both arrays:
{
"path": "/home",
"ip_addresses": ["156.76.87.4", "156.76.12.4", "156.74.1.4"],
"unauthorized_ip_addresses": ["156.76.87.4", "156.76.12.4"]
},
{
"path": "/checkout",
"ip_addresses": ["156.76.87.4"],
"unauthorized_ip_addresses": []
}
Theme
Light