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:
count()
1
2
3
Loading...
echo '1
2
3' \
| super -z -c 'count()' -
Continuous count of simple sequence:
yield count()
1
2
3
Loading...
echo '1
2
3' \
| super -z -c 'yield count()' -
Mixed types are handled:
yield count()
1
"foo"
10.0.0.1
Loading...
echo '1
"foo"
10.0.0.1' \
| super -z -c 'yield count()' -
Count of values in buckets grouped by key:
count() by k | sort
{a:1,k:1}
{a:2,k:1}
{a:3,k:2}
Loading...
echo '{a:1,k:1}
{a:2,k:1}
{a:3,k:2}' \
| super -z -c 'count() by k | sort' -
A simple count with no input values returns no output:
where grep("bar") | count()
1
"foo"
10.0.0.1
Loading...
echo '1
"foo"
10.0.0.1' \
| super -z -c 'where grep("bar") | count()' -
Count can return an explicit zero when using a where
clause in the aggregation:
count() where grep("bar")
1
"foo"
10.0.0.1
Loading...
echo '1
"foo"
10.0.0.1' \
| super -z -c 'count() where grep("bar")' -
Note that the number of input values are counted, unlike the len
function which counts the number of elements in a given value:
count()
[1,2,3]
Loading...
echo '[1,2,3]' \
| super -z -c 'count()' -