Github user mateiz commented on a diff in the pull request: https://github.com/apache/spark/pull/93#discussion_r10486216 --- Diff: python/pyspark/rdd.py --- @@ -628,6 +656,31 @@ def mergeMaps(m1, m2): m1[k] += v return m1 return self.mapPartitions(countPartition).reduce(mergeMaps) + + def top(self, num): + """ + Get the top N elements from a RDD. + + Note: It returns the list sorted in ascending order. + >>> sc.parallelize([10, 4, 2, 12, 3]).top(1) + [12] + >>> sc.parallelize([2, 3, 4, 5, 6]).cache().top(2) + [5, 6] + """ + def f(iterator): + q = BoundedPriorityQueue(num) + for k in iterator: + q.put(k) + return q + + def f2(a, b): + a.put(b) + return a --- End diff -- Are you sure this is correct? It seems like f2 will put the entire queue into `b` as an element in queue `a`. Try it with an RDD with more than one partition.
--- 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. ---