Fix JIRA-983 and support exteranl sort for sortByKey

Change class ExternalAppendOnlyMap and make it support customized comparator function(not only sorted by hashCode).
nit: style should be something like
```
shuffled.mapPartitions { iter =>
  ...
}.flatMap { case (k, c) =>
  c.iterator.map { x => (k, x).asInstanceOf[P] }
}
```