REQ functions in the Apache DataSketches DuckDB extension
Function category
REQ
13 functions[Relative-error quantile sketch](https://datasketches.apache.org/docs/REQ/ReqSketch.html). Error scales with rank rather than being fixed across the distribution — predictable accuracy on highly skewed data.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
INTEGER
|
Mode Positional | Description |
Argument
col1
|
Type
sketch_req_bigint | TINYINT | sketch_req_double | …
20 concrete typesBIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTsketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Return type varies by input — 10 concrete types
sketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
Description
Aggregate input values into a Relative Error Quantile sketch. Error scales with rank rather than being a fixed fraction of n — predictable accuracy on highly skewed distributions where a fixed-error sketch over- or under-spends precision at the extremes.
SELECT datasketch_req(k, data);
Related functions
- datasketch_req_quantile() — Approximate quantile at a given rank from a REQ sketch
- datasketch_req_rank() — Approximate rank of a value within the REQ sketch
- datasketch_req_cdf() — Return the Cumulative Distribution Function (CDF) of the sketch for a series of points
- datasketch_req_pmf() — Return the Probability Mass Function (PMF) of the sketch for a series of points
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Argument
col1
|
Type
<numeric>[]
10 concrete typesBIGINT[]DOUBLE[]FLOAT[]INTEGER[]SMALLINT[]TINYINT[]UBIGINT[]UINTEGER[]USMALLINT[]UTINYINT[]
|
Mode Positional | Description |
Argument
col2
|
Type
BOOLEAN
|
Mode Positional | Description |
Return type varies by input — 10 concrete types
BIGINT[]DOUBLE[]FLOAT[]INTEGER[]SMALLINT[]TINYINT[]UBIGINT[]UINTEGER[]USMALLINT[]UTINYINT[]
Description
Return the Cumulative Distribution Function (CDF) of the sketch for a series of points
SELECT datasketch_req_cdf(sketch, points, inclusive);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Argument
col1
|
Type
BOOLEAN
|
Mode Positional | Description |
Argument
col2
|
Type
BOOLEAN
|
Mode Positional | Description |
Description
Return a description of this sketch
SELECT datasketch_req_describe(sketch, include_levels, include_items);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Description
Return a boolean indicating if the sketch is empty
SELECT datasketch_req_is_empty(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Description
Return a boolean indicating if the sketch is in estimation mode
SELECT datasketch_req_is_estimation_mode(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Description
Return the value of K for this sketch
SELECT datasketch_req_k(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Return type varies by input — 10 concrete types
BIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINT
Description
Return the maxium item in the sketch
SELECT datasketch_req_max_item(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Return type varies by input — 10 concrete types
BIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINT
Description
Return the minimum item in the sketch
SELECT datasketch_req_min_item(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Description
Return the number of items contained in the sketch
SELECT datasketch_req_rank(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Description
Return the number of retained items in the sketch
SELECT datasketch_req_num_retained(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Argument
col1
|
Type
<numeric>[]
10 concrete typesBIGINT[]DOUBLE[]FLOAT[]INTEGER[]SMALLINT[]TINYINT[]UBIGINT[]UINTEGER[]USMALLINT[]UTINYINT[]
|
Mode Positional | Description |
Argument
col2
|
Type
BOOLEAN
|
Mode Positional | Description |
Return type varies by input — 10 concrete types
BIGINT[]DOUBLE[]FLOAT[]INTEGER[]SMALLINT[]TINYINT[]UBIGINT[]UINTEGER[]USMALLINT[]UTINYINT[]
Description
Return the Probability Mass Function (PMF) of the sketch for a series of points
SELECT datasketch_req_pmf(sketch, points, inclusive);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Argument
col1
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
col2
|
Type
BOOLEAN
|
Mode Positional | Description |
Return type varies by input — 10 concrete types
BIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINT
Description
Approximate quantile at a given rank from a REQ sketch.
SELECT datasketch_req_rank(sketch, rank, inclusive);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
10 concrete typessketch_req_bigintsketch_req_doublesketch_req_floatsketch_req_integersketch_req_smallintsketch_req_tinyintsketch_req_ubigintsketch_req_uintegersketch_req_usmallintsketch_req_utinyint
|
Mode Positional | Description |
Argument
col1
|
Type
<numeric>
10 concrete typesBIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINT
|
Mode Positional | Description |
Argument
col2
|
Type
BOOLEAN
|
Mode Positional | Description |
Description
Approximate rank of a value within the REQ sketch.
SELECT datasketch_req_rank(sketch, item, inclusive);