kll_sketch_merge_bigint function
Applies to: Databricks Runtime 18.0 and later
Merges two compatible integer KLL sketches into a single sketch.
Syntax
kll_sketch_merge_bigint ( sketch1, sketch2 )
Arguments
sketch1: ABINARYexpression containing a serialized integer KLL sketch.sketch2: ABINARYexpression containing a serialized integer KLL sketch.
Returns
A BINARY value containing the merged sketch.
Notes
- Both sketches must be for the same data type (integer).
- The merged sketch has the same k parameter as the input sketches.
- Sketches with different k values cannot be merged.
- Useful for distributed aggregation: create sketches per partition, then merge.
Examples
SQL
-- Merge sketches from different data partitions
-- Use merged sketch for quantile estimation across all data
> WITH partition1 AS (
SELECT kll_sketch_agg_bigint(value) AS sketch FROM VALUES (1), (2) AS T(value)
),
partition2 AS (
SELECT kll_sketch_agg_bigint(value) AS sketch FROM VALUES (3), (4) AS T(value)
),
merged AS (
SELECT kll_sketch_merge_bigint(p1.sketch, p2.sketch) AS sketch
FROM partition1 p1, partition2 p2
)
SELECT kll_sketch_get_quantile_bigint(sketch, 0.5) FROM merged
2