shunping commented on code in PR #30317:
URL: https://github.com/apache/beam/pull/30317#discussion_r1587889713


##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/FnApiStateAccessor.java:
##########
@@ -600,8 +603,74 @@ public <KeyT, ValueT> MultimapState<KeyT, ValueT> 
bindMultimap(
   @Override
   public <T> OrderedListState<T> bindOrderedList(
       String id, StateSpec<OrderedListState<T>> spec, Coder<T> elemCoder) {
-    throw new UnsupportedOperationException(
-        "TODO: Add support for a sorted-list state to the Fn API.");
+    return (OrderedListState<T>)
+        stateKeyObjectCache.computeIfAbsent(
+            createOrderedListUserStateKey(id),
+            new Function<StateKey, Object>() {
+              @Override
+              public Object apply(StateKey key) {
+                return new OrderedListState<T>() {
+                  private final OrderedListUserState<T> impl =
+                      createOrderedListUserState(key, elemCoder);
+
+                  @Override
+                  public void clear() {

Review Comment:
   The clear() function in OrderedListState is quite similar to its counterpart 
in MultiMap, and I don't think we ever has the notion of deleting all states 
associated with a state object. There is one function called "asyncClose()" 
which will sync the local copy with the remote one and then *invalidate* any 
states associated with the state object.
   
   On a different topic, I notice that we have a clear() function in the 
implementation, which handles the special case of deleting all elements from an 
OrderedList more efficiently than clearRange(min, max). I should probably use 
that instead.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to