set_union

This page explains how to use the set_union function in APL.

Use the set_union function in APL to combine two dynamic arrays into one, returning a new array that includes all distinct elements from both. The order of elements in the result isn’t guaranteed and may differ from the original input arrays.

You can use set_union when you need to merge two arrays and eliminate duplicates. It’s especially useful in scenarios where you need to perform set-based logic, such as comparing user activity across multiple sources, correlating IPs from different datasets, or combining traces or log attributes from different events.

Usage

Syntax

set_union(Array1, Array2)

Parameters

NameTypeDescription
Array1dynamicThe first array to merge.
Array2dynamicThe second array to merge.

Returns

A dynamic array that contains the distinct elements of both input arrays.

Example

Use set_union to return the union of two arrays.

Query

['sample-http-logs']
| extend together = set_union(dynamic([1, 2, 3]), dynamic([2, 3, 4, 5]))

Run in Playground

Output

_timetogether
May 22, 11:42:52[1, 2, 3, 4, 5 ]
  • set_difference: Returns elements in the first array that aren’t in the second. Use it to find exclusions.
  • set_has_element: Tests whether a set contains a specific value. Prefer it when you only need a Boolean result.
  • set_union: Returns the union of two or more sets. Use it when you need any element that appears in at least one set instead of every set.

Other query languages