tomstepp commented on code in PR #36112:
URL: https://github.com/apache/beam/pull/36112#discussion_r2341658667


##########
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:
   Took farm hash of offset and put in different DoFn.



-- 
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

Reply via email to