[SPARK-983] Support external sorting

This satisfies SPARK-983 Support external sorting for RDD#sortByKey()
It also adds a general sortPartitions() method to RDD.
This is also used in ExternalAppendOnlyMap. We should abstract it into Utils.scala or something