APPROX_TOP_K
functionsupportedCore SQL functionsUses Space-Saving to return an approximation of the most frequent values in the input, along with their approximate frequencies. The output is a JSON array of arrays. In the inner arrays, the first entry is a value in the input, and the second entry corresponds to its estimated frequency in the input. The outer array contains k items, sorted by descending frequency. For more information about APPROX_TOP_K, see Estimating Frequent Values.
Syntax
supportedpartialnot supportednot scored
Aggregate function
APPROX_TOP_K( <expr> [ , <k> [ , <counters> ] ] )
Window function
APPROX_TOP_K( <expr> [ , <k> [ , <counters> ] ] ) OVER ( [ PARTITION BY <expr4> ] )
Parameters
| Name | Required | Description |
|---|---|---|
expr4 | required | This is the optional expression used to group rows into partitions. |
Usage notes
- The approximation is more accurate if the number of counters is large, so in most cases counters should be considerably bigger than k. (Each counter uses only a small amount of memory, so increasing the number of counters is not expensive in terms of memory.)
- When this function is called as a window function, it does not support: An ORDER BY clause within the OVER clause.
- Explicit window frames.
- Decimal-float (DECFLOAT) values aren’t supported.