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

Aggregate Function

dcount — count distinct input values

Synopsis

dcount(any) -> uint64

Description

The dcount aggregate function uses hyperloglog to estimate distinct values of the input in a memory efficient manner.

Examples

Count of values in a simple sequence:

# spq
dcount(this)
# input
1
2
2
3
# expected output
3::uint64

Mixed types are handled:

# spq
dcount(this)
# input
1
"foo"
10.0.0.1
# expected output
3::uint64

The estimated result may become less accurate with more unique input values:

seq 10000 | super -s -c 'dcount(this)' -

=>

9987::uint64

Count of values in buckets grouped by key:

# spq
dcount(a) by k | sort
# input
{a:1,k:1}
{a:2,k:1}
{a:3,k:2}
# expected output
{k:1,dcount:2::uint64}
{k:2,dcount:1::uint64}