tomstepp commented on code in PR #36112: URL: https://github.com/apache/beam/pull/36112#discussion_r2337611500
########## sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Redistribute.java: ########## @@ -190,21 +202,31 @@ public void processElement( } static class AssignShardFn<T> extends DoFn<T, KV<Integer, T>> { - private int shard; + private int randomShard; private @Nullable Integer numBuckets; + private boolean deterministicSharding; - public AssignShardFn(@Nullable Integer numBuckets) { + public AssignShardFn(@Nullable Integer numBuckets, boolean deterministicSharding) { this.numBuckets = numBuckets; + this.deterministicSharding = deterministicSharding; + this.randomShard = 0; } @Setup public void setup() { - shard = ThreadLocalRandom.current().nextInt(); + if (deterministicSharding) { + randomShard = ThreadLocalRandom.current().nextInt(); + } } @ProcessElement public void processElement(@Element T element, OutputReceiver<KV<Integer, T>> r) { - ++shard; + int shard = 0; + if (deterministicSharding && element != null) { + shard = element.hashCode(); Review Comment: Noting KafkaRecord hashCode override: https://github.com/apache/beam/blob/becfcf86ab6f5c2f24986915fd0dfbbfd19de532/sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaRecord.java#L107-L110 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org