Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

union

set union of input values

Synopsis

union(any) -> set[any]

Description

The union aggregate function computes a set union of its input values. If the values are of uniform type, then the output is a set of that type. If the values are of mixed type, the the output is a set of union of the types encountered.

Examples

Create a set of values from a simple sequence:

# spq
union(this)
# input
1
2
3
3
# expected output
set[1,2,3]

Mixed types create a union type for the set elements:

# spq
set:=union(this) | values this,typeof(set)
# input
1
2
3
"foo"
# expected output
{set:set[1,2,3,"foo"]}
<set[int64|string]>

Create sets of values bucketed by key:

# spq
union(a) by k | sort
# input
{a:1,k:1}
{a:2,k:1}
{a:3,k:2}
{a:4,k:2}
# expected output
{k:1,union:set[1,2]}
{k:2,union:set[3,4]}