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

    https://github.com/apache/spark/pull/1791#discussion_r16210568
  
    --- Diff: python/pyspark/rdd.py ---
    @@ -1755,6 +1941,114 @@ def _defaultReducePartitions(self):
         # on the key; we need to compare the hash of the key to the hash of the
         # keys in the pairs.  This could be an expensive operation, since those
         # hashes aren't retained.
    +    # def lookup(self, key):
    +    #     """
    +    #     Return the list of values in the RDD for key key.
    +    #     """
    +
    +    def _is_pickled(self):
    +        """ Return this RDD is serialized by Pickle or not. """
    +        der = self._jrdd_deserializer
    +        if isinstance(der, PickleSerializer):
    +            return True
    +        if isinstance(der, BatchedSerializer) and 
isinstance(der.serializer, PickleSerializer):
    +            return True
    +        return False
    +
    +    def _to_jrdd(self):
    +        """ Return an JavaRDD """
    +        if not self._is_pickled():
    +            self = self._reserialize(BatchedSerializer(PickleSerializer(), 
1024))
    +        batched = isinstance(self._jrdd_deserializer, BatchedSerializer)
    +        return self.ctx._jvm.PythonRDD.pythonToJava(self._jrdd, batched)
    +
    +    def countApproxDistinct(self, relativeSD=0.05):
    +        """
    +        :: Experimental ::
    +        Return approximate number of distinct elements in the 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
    +        <a href="http://dx.doi.org/10.1145/2452376.2452456";>here</a>.
    +
    +        :param: relativeSD Relative accuracy. Smaller values create
    +                           counters that require more space.
    +                           It must be greater than 0.000017.
    +
    +        >>> n = sc.parallelize(range(1000)).map(str).countApproxDistinct()
    +        >>> 950 < n < 1050
    +        True
    +        """
    +        return self._to_jrdd().countApproxDistinct(relativeSD)
    --- End diff --
    
    What countApproxDistinct() need is the hash code of items, so this means 
that we create a hash code for Python objects by hash(pickle.dumps(obj)), so I 
think this could work.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to