code: @SuppressWarnings("unchecked") // getInputFormat, getOutputKeyComparator
    public static <K,V> void writePartitionFile(JobConf job,
        Sampler<K,V> sampler) throws IOException {
      final InputFormat<K,V> inf = (InputFormat<K,V>) job.getInputFormat();
      int numPartitions = job.getNumReduceTasks();
      K[] samples = sampler.getSample(inf, job);
      LOG.info("Using " + samples.length + " samples");
      RawComparator<K> comparator =
        (RawComparator<K>) job.getOutputKeyComparator();
      Arrays.sort(samples, comparator);
      Path dst = new Path(TotalOrderPartitioner.getPartitionFile(job));
      FileSystem fs = dst.getFileSystem(job);
      if (fs.exists(dst)) {
        fs.delete(dst, false);
      }
      SequenceFile.Writer writer = SequenceFile.createWriter(fs, job, dst,
          job.getMapOutputKeyClass(), NullWritable.class);
      NullWritable nullValue = NullWritable.get();
      float stepSize = samples.length / (float) numPartitions;
      int last = -1;
      for(int i = 1; i < numPartitions; ++i) {
        int k = Math.round(stepSize * i);
        while (last >= k && comparator.compare(samples[last], samples[k]) == 0) {
          ++k;
        }
        writer.append(samples[k], nullValue);
        last = k;
      }
      writer.close();
    }
docs: Write a partition file for the given job, using the Sampler provided.
  Queries the sampler for a sample keyset, sorts by the output key
  comparator, selects the keys for each rank, and writes to the destination
  returned from {@link
  org.apache.hadoop.mapred.lib.TotalOrderPartitioner#getPartitionFile}.