CPC functions in the Apache DataSketches DuckDB extension
Function category
CPC
7 functions[Compressed Probability Counting](https://datasketches.apache.org/docs/CPC/CpcSketches.html) — distinct-counting at roughly 40% the size of HLL at the same accuracy, traded against slower serialization. Choose this when you store many sketches at rest.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
INTEGER
|
Mode Positional | Description |
Argument
col1
|
Type
FLOAT | BLOB | DOUBLE | …
12 concrete typesBIGINTBLOBDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTVARCHAR
|
Mode Positional | Description |
Description
Aggregate input values into a Compressed Probability Counting sketch — a distinct-count sketch that's roughly 40% smaller than HLL at the same accuracy, traded against slower serialization. Choose CPC when you store many sketches at rest and reads are infrequent. The leading lg_k controls the size/accuracy trade-off the same way it does for HLL.
SELECT datasketch_cpc_estimate(datasketch_cpc(12, user_id)) AS distinct_users
FROM events;
Related functions
- datasketch_cpc_estimate() — Read the estimated distinct count from a CPC sketch
- datasketch_cpc_union() — Merge a column of `sketch_cpc` BLOBs into one rollup sketch — the standard per-partition / per-day rollup pattern
- datasketch_cpc_lower_bound() — Return the lower bound of the number of distinct items seen by the sketch
- datasketch_cpc_upper_bound() — Return the upper bound of the number of distinct items seen by the sketch
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_cpc
|
Mode Positional | Description |
Description
Return a string representation of the sketch
SELECT datasketch_cpc_describe(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_cpc
|
Mode Positional | Description |
Description
Read the estimated distinct count from a CPC sketch.
SELECT datasketch_cpc_estimate(sketch);
Related functions
- datasketch_cpc() — Aggregate input values into a Compressed Probability Counting sketch — a distinct-count sketch that's roughly 40% smaller than HLL at the same accuracy, traded against slower serialization
- datasketch_cpc_union() — Merge a column of `sketch_cpc` BLOBs into one rollup sketch — the standard per-partition / per-day rollup pattern
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_cpc
|
Mode Positional | Description |
Description
Return a boolean indicating if the sketch is empty
SELECT datasketch_cpc_is_empty(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_cpc
|
Mode Positional | Description |
Argument
col1
|
Type
UTINYINT
|
Mode Positional | Description |
Description
Return the lower bound of the number of distinct items seen by the sketch
SELECT datasketch_cpc_lower_bound(sketch, std_dev);
Related functions
- datasketch_cpc() — Aggregate input values into a Compressed Probability Counting sketch — a distinct-count sketch that's roughly 40% smaller than HLL at the same accuracy, traded against slower serialization
- datasketch_cpc_upper_bound() — Return the upper bound of the number of distinct items seen by the sketch
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
INTEGER
|
Mode Positional | Description |
Argument
col1
|
Type
sketch_cpc
|
Mode Positional | Description |
Description
Merge a column of sketch_cpc BLOBs into one rollup sketch — the standard per-partition / per-day rollup pattern.
SELECT datasketch_cpc_union(k, data);
Related functions
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
sketch_cpc
|
Mode Positional | Description |
Argument
col1
|
Type
UTINYINT
|
Mode Positional | Description |
Description
Return the upper bound of the number of distinct items seen by the sketch
SELECT datasketch_cpc_upper_bound(sketch, std_dev);
Related functions
- datasketch_cpc() — Aggregate input values into a Compressed Probability Counting sketch — a distinct-count sketch that's roughly 40% smaller than HLL at the same accuracy, traded against slower serialization
- datasketch_cpc_lower_bound() — Return the lower bound of the number of distinct items seen by the sketch