Partitioning of RDDs is done by partitioners. Partitioners assign a partition index to the elements in the RDD. All elements in the same partition will have the same partition index.
Spark comes with two partitioners the HashPartitioner and the RangePartitioner. In addition to these, you can also implement a custom partitioner.