Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15041#discussion_r79410479
  
    --- Diff: core/src/main/scala/org/apache/spark/util/collection/Utils.scala 
---
    @@ -30,10 +34,22 @@ private[spark] object Utils {
        * Returns the first K elements from the input as defined by the 
specified implicit Ordering[T]
        * and maintains the ordering.
        */
    -  def takeOrdered[T](input: Iterator[T], num: Int)(implicit ord: 
Ordering[T]): Iterator[T] = {
    -    val ordering = new GuavaOrdering[T] {
    -      override def compare(l: T, r: T): Int = ord.compare(l, r)
    +  def takeOrdered[T](input: Iterator[T], num: Int,
    +      ser: Serializer = SparkEnv.get.serializer)(implicit ord: 
Ordering[T]): Iterator[T] = {
    +    val context = TaskContext.get()
    +    if (context == null) {
    +      val ordering = new GuavaOrdering[T] {
    +        override def compare(l: T, r: T): Int = ord.compare(l, r)
    +      }
    +      ordering.leastOf(input.asJava, num).iterator.asScala
    +    } else {
    +      val sorter =
    +        new ExternalSorter[T, Any, Any](context, None, None, Some(ord), 
ser)
    +      sorter.insertAll(input.map(x => (x, null)))
    --- End diff --
    
    are you sure this has the same performance as before? You are sorting(and 
keeping) all the records, and get the first K, while previously it's just a 
in-memory top K algorithm.


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

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to