I saw Code of sortByKey:
def sortByKey(ascending: Boolean = true, numPartitions: Int = self.partitions.size): RDD[P] = {
It makes numPartitions = self.partitions.size which comes from getPartitions method of RDD, if you dont specify it explicitly.
In this case it will be rdd which will be created by step (3rd). Isn't it wrong?