[SPARK-983] Support external sorting

This satisfies SPARK-983 Support external sorting for RDD#sortByKey()
It also adds a general sortPartitions() method to RDD.
The reason why the equivalent class in ExternalAppendOnlyMap.scala uses `null` rather Option is because the latter is slightly slower. The difference normally isn't significant, but it becomes noticeable on a super hot code path like this one (i.e. it gets called all the time), so maybe it's worth it to use `null` rather than `None`.