Ngone51 commented on a change in pull request #29028:
URL: https://github.com/apache/spark/pull/29028#discussion_r451528174
##########
File path: core/src/main/scala/org/apache/spark/rdd/RDD.scala
##########
@@ -1509,22 +1509,26 @@ abstract class RDD[T: ClassTag](
* @return an array of top elements
*/
def takeOrdered(num: Int)(implicit ord: Ordering[T]): Array[T] = withScope {
- if (num == 0) {
+ if (num == 0 || partitions.length == 0) {
Array.empty
} else {
- val mapRDDs = mapPartitions { items =>
- // Priority keeps the largest elements, so let's reverse the ordering.
- val queue = new BoundedPriorityQueue[T](num)(ord.reverse)
- queue ++= collectionUtils.takeOrdered(items, num)(ord)
- Iterator.single(queue)
- }
- if (mapRDDs.partitions.length == 0) {
- Array.empty
- } else {
+ if (conf.get(RDD_TAKE_ORDERED_MERGE_IN_DRIVER)) {
+ val mapRDDs = mapPartitions { items =>
+ // Priority keeps the largest elements, so let's reverse the
ordering.
+ val queue = new BoundedPriorityQueue[T](num)(ord.reverse)
+ queue ++= collectionUtils.takeOrdered(items, num)(ord)
+ Iterator.single(queue)
+ }
mapRDDs.reduce { (queue1, queue2) =>
queue1 ++= queue2
queue1
}.toArray.sorted(ord)
+ } else {
+ mapPartitions { items =>
+ collectionUtils.takeOrdered(items, num)(ord)
+ }.repartition(1).mapPartitions { items =>
Review comment:
Then, the executor could easily be under excessive memory pressure by
`repartition(1)`?
Actually, I think it's probably a good idea to use `treeReduce` instead as
mentioned in SPARK-32212.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]