Ordering.natural() returns an Ordering object, which implements the
Comparator interface.

http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/collect/Ordering.html#natural()


On Tue, May 13, 2014 at 10:16 PM, Reynold Xin <notifications@github.com>wrote:

> In core/src/main/scala/org/apache/spark/api/java/JavaRDD.scala:
>
> > @@ -150,6 +153,18 @@ class JavaRDD[T](val rdd: RDD[T])(implicit val classTag: ClassTag[T])
> >      rdd.setName(name)
> >      this
> >    }
> > +
> > +  /**
> > +   * Return this RDD sorted by the given key function.
> > +   */
> > +  def sortBy[S](f: JFunction[T, S], ascending: Boolean, numPartitions: Int): JavaRDD[T] = {
> > +    import scala.collection.JavaConverters._
> > +    def fn = (x: T) => f.call(x)
> > +    implicit val ordering = com.google.common.collect.Ordering.natural().asInstanceOf[Ordering[S]]
>
> How does this actually work? Shouldn't natural() return a Comparator?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/apache/spark/pull/369/files#r12621237>
> .
>