0

Can anyone give a clear example on how to use repartitionAndSortWithinPartitions in Java, not scala.

Thanks in advance!! Ani

Ani
  • 598
  • 5
  • 13
  • 29

1 Answers1

2

Take JavaPairRDD<K, V>:

JavaPairRDD<K, V> rdd = ...;

Define partitioner:

Partitioner partitioner = ...;

Optionally define Comparator<K> if needed.

Comparator<K> comparator = ...;

Apply method:

JavaPairRDD<K, V> repartitioned =
  rdd.repartitionAndSortWithinPartitions(partitioner);

or

JavaPairRDD<K, V> repartitioned =
  rdd.repartitionAndSortWithinPartitions(partitioner, comparator);
zero323
  • 322,348
  • 103
  • 959
  • 935