srowen commented on a change in pull request #23986: [SPARK-27070] Fix 
performance bug in DefaultPartitionCoalescer
URL: https://github.com/apache/spark/pull/23986#discussion_r262932338
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/rdd/CoalescedRDD.scala
 ##########
 @@ -219,9 +221,8 @@ private class DefaultPartitionCoalescer(val balanceSlack: 
Double = 0.10)
    * @param key string representing a partitioned group on preferred machine 
key
    * @return Option of [[PartitionGroup]] that has least elements for key
    */
-  def getLeastGroupHash(key: String): Option[PartitionGroup] = {
-    groupHash.get(key).map(_.sortWith(compare).head)
-  }
+  def getLeastGroupHash(key: String): Option[PartitionGroup] =
+    groupHash.get(key).flatMap (group => if (group.isEmpty) None else 
Some(group.min))
 
 Review comment:
   `.map()` should still be OK here as `None` will results in `None`. Rather 
than the implicit ordering, just use `.minBy`?
   `.map(_.minBy(_.numPartitions))`?

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to