[ 
https://issues.apache.org/jira/browse/SPARK-61368?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Milos Stojko updated SPARK-61368:
---------------------------------
    Description: 
PR that adds this - [https://github.com/apache/spark/pull/60301]

Problem - all regarding {{kll_merge_agg_bigint}}, {{kll_merge_agg_float}} and 
{{kll_merge_agg_double}} without k:
 * The result takes the k of the first input sketch that the aggregate reads.
 * This can cause high instability in terms of memory, performance, and output 
accuracy: if the first sketch chosen is k=8, it will have high error bounds and 
use very little memory, but it's also possible that the very same query uses 
k=65000. Which k is chosen is non-deterministic (depends on first sketch 
encountered, which is undefined)

Proposal:
 * Add an internal SQL conf, on by default: 
{{spark.sql.function.kllMerge.lowestK.enabled}}.
 * When it is on, a merge without k returns the smallest k among the non-empty 
input sketches, compacting or exact. If every input sketch is empty, it returns 
the smallest k of them. With no non-NULL input, it returns an empty sketch with 
k = 200. An explicit k does not change.
 * So the k does not depend on the order or the partitioning of the inputs.
 * Trade-off: a small sketch that never compacted can lower the k, so the 
result can be less exact than the larger input. Pass k to keep a larger k.
 * The scalar {{kll_sketch_merge_*}} functions do not change (SPARK-61981 only 
documents them): they keep the k of the left sketch. So for the same two 
sketches, the scalar and the aggregate merge can return a different k.


  was:
PR that adds this - [https://github.com/apache/spark/pull/60301]

Problem - all regarding {{{}kll_merge_agg_bigint{}}}, {{kll_merge_agg_float}} 
and {{kll_merge_agg_double}} without k:
 * The result takes the k of the first input sketch that the aggregate reads.
 * This can cause high instability in terms of memory, performance, and output 
accuracy: if the first sketch chosen is k=8, it will have high error bounds and 
use very little memory, but it's also possible that the very same query uses 
k=65000. Which k is chosen is non-deterministic (depends on first sketch 
encountered, which is undefined)

Proposal:
 * Add an internal SQL conf, on by default: 
{{spark.sql.function.kllMerge.lowestCompactingK.enabled}}, shared with 
SPARK-61981.
 * When it is on, a merge without k returns the smallest k among the non-empty 
input sketches, compacting or exact. If every input sketch is empty, it returns 
the smallest k of them. An explicit k does not change.
 * So the k does not depend on the order or the partitioning of the inputs.

{code:sql}
 {code}


> kll_merge_agg without k: add a conf to take the lowest k among inputs that 
> have started compacting
> --------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-61368
>                 URL: https://issues.apache.org/jira/browse/SPARK-61368
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 5.0.0
>            Reporter: Milos Stojko
>            Priority: Major
>              Labels: pull-request-available
>
> PR that adds this - [https://github.com/apache/spark/pull/60301]
> Problem - all regarding {{kll_merge_agg_bigint}}, {{kll_merge_agg_float}} and 
> {{kll_merge_agg_double}} without k:
>  * The result takes the k of the first input sketch that the aggregate reads.
>  * This can cause high instability in terms of memory, performance, and 
> output accuracy: if the first sketch chosen is k=8, it will have high error 
> bounds and use very little memory, but it's also possible that the very same 
> query uses k=65000. Which k is chosen is non-deterministic (depends on first 
> sketch encountered, which is undefined)
> Proposal:
>  * Add an internal SQL conf, on by default: 
> {{spark.sql.function.kllMerge.lowestK.enabled}}.
>  * When it is on, a merge without k returns the smallest k among the 
> non-empty input sketches, compacting or exact. If every input sketch is 
> empty, it returns the smallest k of them. With no non-NULL input, it returns 
> an empty sketch with k = 200. An explicit k does not change.
>  * So the k does not depend on the order or the partitioning of the inputs.
>  * Trade-off: a small sketch that never compacted can lower the k, so the 
> result can be less exact than the larger input. Pass k to keep a larger k.
>  * The scalar {{kll_sketch_merge_*}} functions do not change (SPARK-61981 
> only documents them): they keep the k of the left sketch. So for the same two 
> sketches, the scalar and the aggregate merge can return a different k.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to