TDigest functions in the Apache DataSketches DuckDB extension
Function category
TDigest
9 functions[t-digest](https://datasketches.apache.org/docs/tdigest/tdigest.html) — quantile sketch optimized for the tails (p99, p999). Most accurate where SLOs live; FLOAT/DOUBLE input only. Use when tail latencies or outliers matter more than median accuracy.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
INTEGER
|
Mode Positional | Description |
Argument
col1
|
Type
sketch_tdigest_float | sketch_tdigest_double | DOUBLE | FLOAT
4 concrete typesDOUBLEFLOATsketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Return type varies by input — 2 concrete types
sketch_tdigest_doublesketch_tdigest_float
Description
Aggregate input values into a t-digest quantile sketch — most accurate at the tails (p99, p999), exactly where SLOs live. FLOAT/DOUBLE input only. The first argument controls the centroid budget; larger sketches give tighter tail estimates.
SELECT datasketch_tdigest_quantile(
datasketch_tdigest(100, latency_ms), 0.999
) AS p999
FROM requests;
Related functions
- datasketch_tdigest_quantile() — Approximate quantile at a given rank from a t-digest sketch
- datasketch_tdigest_rank() — Approximate rank of a value within the t-digest sketch
- datasketch_tdigest_cdf() — Return the Cumulative Distribution Function (CDF) of the sketch for a series of points
- datasketch_tdigest_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>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Argument
col1
|
Type
<numeric>[]
2 concrete typesDOUBLE[]FLOAT[]
|
Mode Positional | Description |
Return type varies by input — 2 concrete types
DOUBLE[]FLOAT[]
Description
Return the Cumulative Distribution Function (CDF) of the sketch for a series of points
SELECT datasketch_tdigest_cdf(sketch, points);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Argument
col1
|
Type
BOOLEAN
|
Mode Positional | Description |
Description
Return a description of this sketch
SELECT datasketch_tdigest_describe(sketch, include_centroids);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Description
Return a boolean indicating if the sketch is empty
SELECT datasketch_tdigest_is_empty(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Description
Return the value of K for this sketch
SELECT datasketch_tdigest_k(sketch);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Argument
col1
|
Type
<numeric>[]
2 concrete typesDOUBLE[]FLOAT[]
|
Mode Positional | Description |
Return type varies by input — 2 concrete types
DOUBLE[]FLOAT[]
Description
Return the Probability Mass Function (PMF) of the sketch for a series of points
SELECT datasketch_tdigest_pmf(sketch, points);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Argument
col1
|
Type
DOUBLE
|
Mode Positional | Description |
Return type varies by input — 2 concrete types
DOUBLEFLOAT
Description
Approximate quantile at a given rank from a t-digest sketch.
SELECT datasketch_tdigest_quantile(sketch, rank);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Argument
col1
|
Type
<numeric>
2 concrete typesDOUBLEFLOAT
|
Mode Positional | Description |
Description
Approximate rank of a value within the t-digest sketch.
SELECT datasketch_tdigest_rank(sketch, item);
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
col0
|
Type
<sketch>
2 concrete typessketch_tdigest_doublesketch_tdigest_float
|
Mode Positional | Description |
Description
Return the total weight of this sketch
SELECT datasketch_tdigest_total_weight(sketch);