Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15041#discussion_r79416925
  
    --- 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 --
    
    I was thinking the value of this PR is to sort huge data and return small 
top k. If `GuavaOrdering` can already do this, I would suspect the value of 
this change. @cenyuhai What do you think?


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