Abacn commented on code in PR #35632:
URL: https://github.com/apache/beam/pull/35632#discussion_r2243541588


##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/FnApiStateAccessor.java:
##########
@@ -1086,6 +1225,45 @@ private <T> OrderedListUserState<T> 
createOrderedListUserState(
     return rval;
   }
 
+  public static class OrderedListStateKey implements Weighted {
+    private final String pTransformId;
+    private final String stateId;
+    private final ByteString window;
+    private final ByteString key;
+    private final int hash;
+
+    public OrderedListStateKey(StateKey.OrderedListUserState proto) {
+      this.window = proto.getWindow();
+      this.key = proto.getKey();
+      this.pTransformId = proto.getTransformId();
+      this.stateId = proto.getUserStateId();
+      this.hash = Objects.hash(OrderedListStateKey.class, window, key, 
pTransformId, stateId);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (!(o instanceof FnApiStateAccessor.OrderedListStateKey)) {
+        return false;
+      }
+      OrderedListStateKey other = (OrderedListStateKey) o;
+      return hash == other.hash
+          && pTransformId.equals(other.pTransformId)
+          && stateId.equals(other.stateId)
+          && window.equals(other.window)
+          && key.equals(other.key);
+    }
+
+    @Override
+    public int hashCode() {
+      return hash;
+    }
+
+    @Override
+    public long getWeight() {

Review Comment:
   These three Weighted implementations look identical. Any consideration to do 
so or consider merge them?



##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/FnApiStateAccessor.java:
##########
@@ -1038,6 +1098,45 @@ private <T> BagUserState<T> createBagUserState(StateKey 
stateKey, Coder<T> value
     return rval;
   }
 
+  private static class BagStateKey implements Weighted {
+    private final String pTransformId;
+    private final String stateId;
+    private final ByteString window;
+    private final ByteString key;
+    private final int hash;
+
+    public BagStateKey(StateKey.BagUserState proto) {
+      this.window = proto.getWindow();
+      this.key = proto.getKey();
+      this.pTransformId = proto.getTransformId();
+      this.stateId = proto.getUserStateId();
+      this.hash = Objects.hash(BagStateKey.class, window, key, pTransformId, 
stateId);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (!(o instanceof BagStateKey)) {
+        return false;
+      }
+      BagStateKey other = (BagStateKey) o;
+      return hash == other.hash
+          && pTransformId.equals(other.pTransformId)
+          && stateId.equals(other.stateId)
+          && window.equals(other.window)
+          && key.equals(other.key);
+    }
+
+    @Override
+    public int hashCode() {
+      return hash;
+    }
+
+    @Override
+    public long getWeight() {
+      return 40L + pTransformId.length() + stateId.length() + window.size() + 
key.size();

Review Comment:
   where does this 40 come from?



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