You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/10/12 20:55:43 UTC
[GitHub] [beam] zhengbuqian commented on a diff in pull request #23491: Add MultimapState API
zhengbuqian commented on code in PR #23491:
URL: https://github.com/apache/beam/pull/23491#discussion_r993888164
##########
runners/core-java/src/main/java/org/apache/beam/runners/core/InMemoryStateInternals.java:
##########
@@ -463,6 +476,116 @@ public InMemoryBag<T> copy() {
}
}
+ /** An {@link InMemoryState} implementation of {@link MultimapState}. */
+ public static final class InMemoryMultimap<K, V>
+ implements MultimapState<K, V>, InMemoryState<InMemoryMultimap<K, V>> {
+ private final Coder<K> keyCoder;
+ private final Coder<V> valueCoder;
+ private Multimap<K, V> contents = ArrayListMultimap.create();
+
+ public InMemoryMultimap(Coder<K> keyCoder, Coder<V> valueCoder) {
+ this.keyCoder = keyCoder;
+ this.valueCoder = valueCoder;
+ }
+
+ @Override
+ public void clear() {
+ contents = ArrayListMultimap.create();
+ }
+
+ @Override
+ public void put(K key, V value) {
+ contents.put(key, value);
+ }
+
+ @Override
+ public void remove(K key) {
+ contents.removeAll(key);
+ }
+
+ @Override
+ public @UnknownKeyFor @NonNull @Initialized ReadableState<Iterable<V>> get(K key) {
+ return contents.containsKey(key)
Review Comment:
Done
--
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-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org