Skip to content

KLL functions in the Apache DataSketches DuckDB extension

Function category

KLL

14 functions

[KLL quantile sketch](https://datasketches.apache.org/docs/KLL/KLLSketch.html) — modern mergeable quantile estimator. Best balance of accuracy, speed, and size for general-purpose quantile work. Default choice unless you have a specific reason to pick TDigest or REQ.

datasketch_kll

Aggregate function KLL
Signature
datasketch_kll(col0: INTEGER, col1: sketch_kll_bigint | sketch_kll_double | sketch_kll_usmallint | …) <sketch>
Arguments (Positional)
Argument col0 Type INTEGER Mode Positional Description
Argument col1 Type sketch_kll_bigint | sketch_kll_double | sketch_kll_usmallint | …
20 concrete types
BIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINTsketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Return type varies by input — 10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Description
1 p50 / p95 / p99 latency from one KLL sketch
WITH agg AS (
  SELECT datasketch_kll(200, latency_ms) AS sketch FROM requests
)
SELECT datasketch_kll_quantile(sketch, 0.50, true) AS p50,
       datasketch_kll_quantile(sketch, 0.95, true) AS p95,
       datasketch_kll_quantile(sketch, 0.99, true) AS p99
FROM agg;

datasketch_kll_cdf

Scalar function KLL
Signature
datasketch_kll_cdf( col0: <sketch>, col1: <numeric>[], col2: BOOLEAN ) <numeric>[]
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Argument col1 Type <numeric>[]
10 concrete types
BIGINT[]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
1 Example 1
SELECT datasketch_kll_cdf(sketch, points, inclusive);

datasketch_kll_describe

Scalar function KLL
Signature
datasketch_kll_describe( col0: <sketch>, col1: BOOLEAN, col2: BOOLEAN ) VARCHAR
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Argument col1 Type BOOLEAN Mode Positional Description
Argument col2 Type BOOLEAN Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_describe(sketch, include_levels, include_items);

datasketch_kll_is_empty

Scalar function KLL
Signature
datasketch_kll_is_empty(col0: <sketch>) BOOLEAN
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_is_empty(sketch);

datasketch_kll_is_estimation_mode

Scalar function KLL
Signature
datasketch_kll_is_estimation_mode(col0: <sketch>) BOOLEAN
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_is_estimation_mode(sketch);

datasketch_kll_k

Scalar function KLL
Signature
datasketch_kll_k(col0: <sketch>) USMALLINT
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_k(sketch);

datasketch_kll_max_item

Scalar function KLL
Signature
datasketch_kll_max_item(col0: <sketch>) <numeric>
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Return type varies by input — 10 concrete types
BIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINT
Description
1 Example 1
SELECT datasketch_kll_max_item(sketch);

datasketch_kll_min_item

Scalar function KLL
Signature
datasketch_kll_min_item(col0: <sketch>) <numeric>
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Return type varies by input — 10 concrete types
BIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINT
Description
1 Example 1
SELECT datasketch_kll_min_item(sketch);

datasketch_kll_n

Scalar function KLL
Signature
datasketch_kll_n(col0: <sketch>) UBIGINT
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_rank(sketch);

datasketch_kll_normalized_rank_error

Scalar function KLL
Signature
datasketch_kll_normalized_rank_error(col0: <sketch>, col1: BOOLEAN) DOUBLE
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Argument col1 Type BOOLEAN Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_normalized_rank_error(sketch, is_pmf);

datasketch_kll_num_retained

Scalar function KLL
Signature
datasketch_kll_num_retained(col0: <sketch>) UBIGINT
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_num_retained(sketch);

datasketch_kll_pmf

Scalar function KLL
Signature
datasketch_kll_pmf( col0: <sketch>, col1: <numeric>[], col2: BOOLEAN ) <numeric>[]
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Argument col1 Type <numeric>[]
10 concrete types
BIGINT[]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
1 Example 1
SELECT datasketch_kll_pmf(sketch, points, inclusive);

datasketch_kll_quantile

Scalar function KLL
Signature
datasketch_kll_quantile( col0: <sketch>, col1: DOUBLE, col2: BOOLEAN ) <numeric>
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_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
1 Example 1
SELECT datasketch_kll_rank(sketch, rank, inclusive);

datasketch_kll_rank

Scalar function KLL
Signature
datasketch_kll_rank( col0: <sketch>, col1: <numeric>, col2: BOOLEAN ) DOUBLE
Arguments (Positional)
Argument col0 Type <sketch>
10 concrete types
sketch_kll_bigintsketch_kll_doublesketch_kll_floatsketch_kll_integersketch_kll_smallintsketch_kll_tinyintsketch_kll_ubigintsketch_kll_uintegersketch_kll_usmallintsketch_kll_utinyint
Mode Positional Description
Argument col1 Type <numeric>
10 concrete types
BIGINTDOUBLEFLOATINTEGERSMALLINTTINYINTUBIGINTUINTEGERUSMALLINTUTINYINT
Mode Positional Description
Argument col2 Type BOOLEAN Mode Positional Description
Description
1 Example 1
SELECT datasketch_kll_rank(sketch, item, inclusive);