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

    https://github.com/apache/spark/pull/97#discussion_r11224851
  
    --- Diff: python/pyspark/rdd.py ---
    @@ -713,6 +780,31 @@ def merge(a, b):
     
             return sorted(self.mapPartitions(topIterator).reduce(merge), 
reverse=True)
     
    +    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)]
    --- End diff --
    
    Actually there is a problem here -- when you specify a key function, it 
should only be used for sorting, it should not be returned in the final output. 
So this code for example should return
    ```
    [10, 9, 7, 6, 5, 4]
    ```
    You probably need to make a pass after the merge if a key is given to 
create a new array.


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