Frequent Items functions in the Apache DataSketches DuckDB extension
Function category
Frequent Items
9 functions[Heavy-hitter sketch](https://datasketches.apache.org/docs/Frequency/FrequentItemsOverview.html) that identifies the most-frequent items in a stream along with confidence-bounded frequency estimates. Use for top-N analysis on high-cardinality streams where exact `GROUP BY count()` is too expensive.
Signature
2 overloaded forms · click to inspectArguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
FLOAT | UINTEGER | SMALLINT | …
12 concrete typesBIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTVARCHARsketch_frequent_items
|
Mode Positional | Description |
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
INTEGER
|
Mode Positional | Description |
Argument
col1
|
Type
TINYINT | VARCHAR | SMALLINT | …
12 concrete typesBIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTVARCHARsketch_frequent_items
|
Mode Positional | Description |
Description
Aggregate input values into a Frequent Items (heavy-hitter) sketch. The first argument is lg_max_map_size — log₂ of the maximum number of tracked items, so 8 → up to 256 candidates, 12 → up to 4096. Bigger values track more candidates and tighten the per-item error bound. Typical values run 4–12.
SELECT datasketch_frequent_items_get_frequent(
datasketch_frequent_items(8, country_code),
'NO_FALSE_POSITIVES'
) AS heavy_hitters
FROM page_views;
Related functions
- datasketch_frequent_items_get_frequent() — Return the heavy-hitter candidates with per-item estimate, lower bound, and upper bound
- datasketch_frequent_items_estimate() — Estimated frequency for a specific item
- datasketch_frequent_items_lower_bound() — Returns the lower bound frequency estimate for a specific item
- datasketch_frequent_items_upper_bound() — Returns the upper bound frequency estimate for a specific item
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Description
Returns the epsilon value (relative error) of the sketch
SELECT datasketch_frequent_items_epsilon(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Argument
col1
|
Type
UBIGINT | BIGINT | SMALLINT | …
11 concrete typesBIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTVARCHAR
|
Mode Positional | Description |
Description
Estimated frequency for a specific item.
SELECT datasketch_frequent_items_estimate(sketch, 'item');
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Argument
col1
|
Type
VARCHAR
|
Mode Positional | Description |
Description
Return the heavy-hitter candidates with per-item estimate, lower bound, and upper bound. The second argument selects the error mode: 'NO_FALSE_POSITIVES' returns only items that are definitely heavy (every returned item really is frequent); 'NO_FALSE_NEGATIVES' returns the union of all candidates that might be — every truly-frequent item is included, plus some that may not be.
SELECT datasketch_frequent_items_get_frequent(sketch, 'NO_FALSE_POSITIVES');
Related functions
- datasketch_frequent_items() — Aggregate input values into a Frequent Items (heavy-hitter) sketch
- datasketch_frequent_items_estimate() — Estimated frequency for a specific item
- datasketch_frequent_items_lower_bound() — Returns the lower bound frequency estimate for a specific item
- datasketch_frequent_items_upper_bound() — Returns the upper bound frequency estimate for a specific item
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Description
Returns true if the sketch is empty
SELECT datasketch_frequent_items_is_empty(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Argument
col1
|
Type
TINYINT | FLOAT | UTINYINT | …
11 concrete typesBIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTVARCHAR
|
Mode Positional | Description |
Description
Returns the lower bound frequency estimate for a specific item
SELECT datasketch_frequent_items_lower_bound(sketch, 'item');
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Description
Returns the number of active items currently tracked by the sketch
SELECT datasketch_frequent_items_num_active(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Description
Returns the total weight (sum of all item counts) processed by the sketch
SELECT datasketch_frequent_items_total_weight(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_frequent_items
|
Mode Positional | Description |
Argument
col1
|
Type
UTINYINT | SMALLINT | INTEGER | …
11 concrete typesBIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTVARCHAR
|
Mode Positional | Description |
Description
Returns the upper bound frequency estimate for a specific item
SELECT datasketch_frequent_items_upper_bound(sketch, 'item');