scwhittle commented on code in PR #35632: URL: https://github.com/apache/beam/pull/35632#discussion_r2243690278
########## 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: 4*reference + int, though it should be 36. I think I had a long at first for hash. added comments ########## 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: I wanted them to use the class/type as part of equality without having to store it per-entry, but I changed it to share a base that does that to avoid the repitition. -- 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