zhengbuqian commented on code in PR #23491:
URL: https://github.com/apache/beam/pull/23491#discussion_r1029954977


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/state/MultimapState.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.state;
+
+import java.util.Map;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.annotations.Experimental.Kind;
+
+/**
+ * A {@link ReadableState} cell mapping keys to bags of values. Keys are 
considered equivalent if
+ * their structural values are equivalent, see
+ * {@link org.apache.beam.sdk.coders.Coder#structuralValue} for additional 
details.
+ *
+ * <p>Implementations of this form of state are expected to implement multimap 
operations
+ * efficiently as supported by some associated backing key-value store.
+ *
+ * @param <K> the type of keys maintained by this multimap
+ * @param <V> the type of mapped values
+ */
+@Experimental(Kind.STATE)
+public interface MultimapState<K, V> extends State {
+
+  /**
+   * Associates the specified value with the specified key in this multimap. 
Existing values
+   * associated with the same key will not be overwritten.
+   *
+   * <p>Changes will not be reflected in the results returned by previous 
calls to {@link
+   * ReadableState#read} on the results any of the reading methods({@link 
#get}, {@link #keys},
+   * {@link #entries}).
+   */
+  void put(K key, V value);
+
+  /**
+   * A deferred lookup, returns an empty iterable if the item is not found.

Review Comment:
   The content of ReadableState should be evaluated when `read()` is called, so 
in this case values.read() will contain newValue. If read() is called before 
the put then newValue will not be contained:
   
   ReadableState<Iterable> values = mm.get(k);
   Iterable it = values.read()
   mm.put(k, newValue);
   for (V v : it) {  /* newValue will not be in this loop  */}
   



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