Skip to main content
Version: Next

count

Aggregate Function

count count input values

Synopsis

count() -> uint64

Description

The count aggregate function computes the number of values in its input.

Examples

Count of values in a simple sequence:

echo '1 2 3' | zq -z 'count()' -

=>

3(uint64)

Continuous count of simple sequence:

echo '1 2 3' | zq -z 'yield count()' -

=>

1(uint64)
2(uint64)
3(uint64)

Mixed types are handled:

echo '1 "foo" 10.0.0.1' | zq -z 'yield count()' -

=>

1(uint64)
2(uint64)
3(uint64)

Count of values in buckets grouped by key:

echo '{a:1,k:1} {a:2,k:1} {a:3,k:2}' | zq -z 'count() by k | sort' -

=>

{k:1,count:2(uint64)}
{k:2,count:1(uint64)}

Note that the number of input values are counted, unlike the len function which counts the number of elements in a given value:

echo '[1,2,3]' | zq -z 'count()' -

=>

1(uint64)