Skip to content

Commit

Permalink
SPARK-1322, top in pyspark should sort result in descending order.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrapCodes committed Mar 26, 2014
1 parent 007a733 commit 58e58c6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/pyspark/rdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def top(self, num):
>>> sc.parallelize([10, 4, 2, 12, 3]).top(1)
[12]
>>> sc.parallelize([2, 3, 4, 5, 6]).cache().top(2)
[5, 6]
[6, 5]
"""
def topIterator(iterator):
q = []
Expand All @@ -711,7 +711,7 @@ def topIterator(iterator):
def merge(a, b):
return next(topIterator(a + b))

return sorted(self.mapPartitions(topIterator).reduce(merge))
return sorted(self.mapPartitions(topIterator).reduce(merge), reverse=True)

def take(self, num):
"""
Expand Down

0 comments on commit 58e58c6

Please sign in to comment.