Github user ash211 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/897#discussion_r13114928
  
    --- Diff: core/src/main/scala/org/apache/spark/rdd/PairRDDFunctions.scala 
---
    @@ -218,14 +217,29 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
        * The accuracy of approximation can be controlled through the relative 
standard deviation
        * (relativeSD) parameter, which also controls the amount of memory 
used. Lower values result in
        * more accurate counts but increase the memory footprint and vice 
versa. Uses the provided
    -   * Partitioner to partition the output RDD.
    +   * [[Partitioner]] to partition the output RDD.
    +   *
    +   * The algorithm used is based on streamlib's implementation of 
"HyperLogLog in Practice:
    +   * Algorithmic Engineering of a State of The Art Cardinality Estimation 
Algorithm", available at
    +   * [[http://research.google.com/pubs/pub40671.html]].
        */
       def countApproxDistinctByKey(relativeSD: Double, partitioner: 
Partitioner): RDD[(K, Long)] = {
    -    val createHLL = (v: V) => new SerializableHyperLogLog(new 
HyperLogLog(relativeSD)).add(v)
    -    val mergeValueHLL = (hll: SerializableHyperLogLog, v: V) => hll.add(v)
    -    val mergeHLL = (h1: SerializableHyperLogLog, h2: 
SerializableHyperLogLog) => h1.merge(h2)
    +    val precision = (math.log((1.106 / relativeSD) * (1.106 / relativeSD)) 
/ math.log(2)).toInt
    --- End diff --
    
    Where does this magic value of 1.106 come from?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to