kll_merge_agg_double
Aggregate function: merges binary KllDoublesSketch representations and returns the merged sketch. The optional k parameter controls the size and accuracy of the merged sketch (range 8-65535). If k is not specified, the merged sketch adopts the k value from the first input sketch.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.kll_merge_agg_double(col=<col>, k=<k>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The column containing binary KllDoublesSketch representations. |
|
| The k parameter that controls size and accuracy (range 8-65535). |
Returns
pyspark.sql.Column: The merged binary representation of the KllDoublesSketch.
Examples
Python
from pyspark.databricks.sql import functions as dbf
df1 = spark.createDataFrame([1.0,2.0,3.0], "DOUBLE")
df2 = spark.createDataFrame([4.0,5.0,6.0], "DOUBLE")
sketch1 = df1.agg(dbf.kll_sketch_agg_double("value").alias("sketch"))
sketch2 = df2.agg(dbf.kll_sketch_agg_double("value").alias("sketch"))
merged = sketch1.union(sketch2).agg(dbf.kll_merge_agg_double("sketch").alias("merged"))
n = merged.select(dbf.kll_sketch_get_n_double("merged")).first()[0]
n
Output
6