title: How to Define Custom partitioner for Spark RDDs of equally sized partition where each partition has equal number of elements?
body: <p>I am new to Spark. I have a large dataset of elements[RDD] and I want to divide it into two exactly equal sized partitions maintaining order of elements. I tried using <code>RangePartitioner</code> like</p>
  
  <pre><code>var data = partitionedFile.partitionBy(new RangePartitioner(2, partitionedFile))
  </code></pre>
  
  <p>This doesn't give a satisfactory result because it divides roughly but not exactly equal sized maintaining order of elements.
  For example if there are 64 elements, we use
  <code>Rangepartitioner</code>, then it divides into 31 elements and 33 elements.</p>
  
  <p>I need a partitioner such that I get exactly first 32 elements in one half and other half contains second set of 32 elements.
  Could you please help me by suggesting how to use a customized partitioner such that I get equally sized two halves, maintaining the order of elements?</p>