APPROX_TOP_K_ACCUMULATE

functionsupportedCore SQL functions

docs.snowflake.com ↗

Aggregate functionsWindow function syntax and usage

Returns the Space-Saving summary at the end of aggregation. (For more information about the Space-Saving summary, see Estimating Frequent Values.) The function APPROX_TOP_K discards its internal, intermediate state when the final cardinality estimate is returned. However, in certain advanced use cases, such as estimating incremental frequent values during bulk loading, you might want to keep the intermediate state, in which case you would use APPROX_TOP_K_ACCUMULATE instead of APPROX_TOP_K. In contrast to APPROX_TOP_K, APPROX_TOP_K_ACCUMULATE does not return a frequency estimate of items. Instead, it returns the algorithm state itself. The intermediate state can later be: - Combined (that is, merged) with intermediate states from separate but related batches of data. - Processed by other functions that operate directly on the intermediate state, for example, APPROX_TOP_K_ESTIMATE. (For an example, see the Examples section below.) - Exported to external tools.

Syntax

APPROX_TOP_K_ACCUMULATE( <expr> , <counters> )

Parameters

NameRequiredDescription
exprrequiredThe expression (e.g. column name) for which you want to find the most common values.
countersrequiredThis is the maximum number of distinct values that can be tracked at a time during the estimation process. For example, if counters is set to 100000, then the algorithm tracks 100,000 distinct values, attempting to keep the 100,000 most frequent values. The maximum number of counters is 100000 (100,000).

Usage notes

See also

Referenced by