Skip to content

Latest commit

 

History

History
44 lines (38 loc) · 816 Bytes

collect.md

File metadata and controls

44 lines (38 loc) · 816 Bytes

Aggregate Function

collect — aggregate values into array

Synopsis

collect(any) -> [any]

Description

The collect aggregate function organizes its input into an array. If the input values vary in type, the return type will be an array of union of the types encountered.

Examples

Simple sequence collected into an array:

echo '1 2 3 4' | zq -z 'collect(this)' -

=>

{collect:[1,2,3,4]}

Continuous collection over a simple sequence:

echo '1 2 3 4' | zq -z 'yield collect(this)' -

=>

[1]
[1,2]
[1,2,3]
[1,2,3,4]

Mixed types create a union type for the array elements:

echo '1 2 3 4 "foo"' | zq -z 'collect(this)' -

=>

{collect:[1,2,3,4,"foo"]}