Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
public static final class CustomDynamicPartitioner extends DynamicPartitioner<Long, Long> {
  private long logicalStartTime;

  @Override
  public void initialize(MapReduceTaskContext mapReduceTaskContext) {
    this.logicalStartTime = mapReduceTaskContext.getLogicalStartTime();
  }

  @Override
  public PartitionKey getPartitionKey(Long key, Long value) {
    return PartitionKey.builder().addLongField("time", logicalStartTime).addLongField("other", key).build();
  }
 
  @Override
  public long transformKey(Long key, Long value) {
    // return null, to avoid writing it as output because it is already
    // encoded in the partition that the output is being written to.
    return null; 
  }
}

...