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

    https://github.com/apache/spark/pull/97#discussion_r11193228
  
    --- Diff: python/pyspark/rdd.py ---
    @@ -713,6 +766,34 @@ def merge(a, b):
     
             return sorted(self.mapPartitions(topIterator).reduce(merge))
     
    +    def takeOrdered(self, num, key=None):
    +        """
    +        Get the N elements from a RDD ordered in ascending order or as 
specified
    +        by the optional key function. 
    +
    +        >>> sc.parallelize([10, 1, 2, 9, 3, 4, 5, 6, 7]).takeOrdered(6)
    +        [1, 2, 3, 4, 5, 6]
    +        >>> sc.parallelize([10, 1, 2, 9, 3, 4, 5, 6, 7], 2).takeOrdered(6, 
key=lambda x: -x)
    +        [(-10, 10), (-9, 9), (-7, 7), (-6, 6), (-5, 5), (-4, 4)]
    +        """
    +
    +        def topNKeyedElems(iterator, key_=None):
    +            q = MaxHeapQ()
    +            for k in iterator:
    +                if not (key_ == None):
    --- End diff --
    
    You can just do `if key_ != None`, did it break before?


---
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