Interface MapState<UK,UV>
-
- Type Parameters:
UK- Type of the keys in the state.UV- Type of the values in the state.
- All Superinterfaces:
State
@Experimental public interface MapState<UK,UV> extends State
Stateinterface for partitioned key-value state. The key-value pair can be added, updated and retrieved.The state is accessed and modified by user functions, and checkpointed consistently by the system as part of the distributed snapshots.
The state is only accessible by functions applied on a
KeyedStream. The key is automatically supplied by the system, so the function always sees the value mapped to the key of the current element. That way, the system can handle stream and state partitioning consistently together.The user value could be null, but change log state backend is not compatible with the user value is null, see FLINK-38144 for more details.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StateFuture<Boolean>asyncContains(UK key)Returns whether there exists the given mapping asynchronously.StateFuture<StateIterator<Map.Entry<UK,UV>>>asyncEntries()Returns the current iterator for all the mappings of this state asynchronously.StateFuture<UV>asyncGet(UK key)Returns the current value associated with the given key asynchronously.StateFuture<Boolean>asyncIsEmpty()Returns whether this state contains no key-value mappings asynchronously.StateFuture<StateIterator<UK>>asyncKeys()Returns the current iterator for all the keys of this state asynchronously.StateFuture<Void>asyncPut(UK key, UV value)Update the current value associated with the given key asynchronously.StateFuture<Void>asyncPutAll(Map<UK,UV> map)Update all of the mappings from the given map into the state asynchronously.StateFuture<Void>asyncRemove(UK key)Delete the mapping of the given key from the state asynchronously.StateFuture<StateIterator<UV>>asyncValues()Returns the current iterator for all the values of this state asynchronously.booleancontains(UK key)Returns whether there exists the given mapping.Iterable<Map.Entry<UK,UV>>entries()Returns all the mappings in the state.UVget(UK key)Returns the current value associated with the given key.booleanisEmpty()Returns true if this state contains no key-value mappings, otherwise false.Iterator<Map.Entry<UK,UV>>iterator()Iterates over all the mappings in the state.Iterable<UK>keys()Returns all the keys in the state.voidput(UK key, UV value)Associates a new value with the given key.voidputAll(Map<UK,UV> map)Copies all of the mappings from the given map into the state.voidremove(UK key)Deletes the mapping of the given key.Iterable<UV>values()Returns all the values in the state.-
Methods inherited from interface org.apache.flink.api.common.state.v2.State
asyncClear, clear
-
-
-
-
Method Detail
-
asyncGet
StateFuture<UV> asyncGet(UK key)
Returns the current value associated with the given key asynchronously. When the state is not partitioned the returned value is the same for all inputs in a given operator instance. If state partitioning is applied, the value returned depends on the current operator input, as the operator maintains an independent state for each partition.- Returns:
- The
StateFuturethat will return value corresponding to the current input. When no corresponding value for this key, the future will returnnull.
-
asyncPut
StateFuture<Void> asyncPut(UK key, UV value)
Update the current value associated with the given key asynchronously. When the state is not partitioned the value is updated for all inputs in a given operator instance. If state partitioning is applied, the updated value depends on the current operator input, as the operator maintains an independent state for each partition. When anullvalue is provided, the state for the given key will be removed.- Parameters:
key- The key that will be updated.value- The new value for the key.- Returns:
- The
StateFuturethat will trigger the callback when update finishes.
-
asyncPutAll
StateFuture<Void> asyncPutAll(Map<UK,UV> map)
Update all of the mappings from the given map into the state asynchronously. When the state is not partitioned the value is updated for all inputs in a given operator instance. If state partitioning is applied, the updated mapping depends on the current operator input, as the operator maintains an independent state for each partition. When anullvalue is provided within the map, the state for the corresponding key will be removed.If an empty map is passed in, the state value remains unchanged.
Null map pointer is not allowed.
- Parameters:
map- The mappings to be stored in this state.- Returns:
- The
StateFuturethat will trigger the callback when update finishes.
-
asyncRemove
StateFuture<Void> asyncRemove(UK key)
Delete the mapping of the given key from the state asynchronously. When the state is not partitioned the deleted value is the same for all inputs in a given operator instance. If state partitioning is applied, the value deleted depends on the current operator input, as the operator maintains an independent state for each partition.- Parameters:
key- The key of the mapping.- Returns:
- The
StateFuturethat will trigger the callback when update finishes.
-
asyncContains
StateFuture<Boolean> asyncContains(UK key)
Returns whether there exists the given mapping asynchronously. When the state is not partitioned the returned value is the same for all inputs in a given operator instance. If state partitioning is applied, the value returned depends on the current operator input, as the operator maintains an independent state for each partition.- Parameters:
key- The key of the mapping.- Returns:
- The
StateFuturethat will return true if there exists a mapping whose key equals to the given key.
-
asyncEntries
StateFuture<StateIterator<Map.Entry<UK,UV>>> asyncEntries()
Returns the current iterator for all the mappings of this state asynchronously. When the state is not partitioned the returned iterator is the same for all inputs in a given operator instance. If state partitioning is applied, the iterator returned depends on the current operator input, as the operator maintains an independent state for each partition.- Returns:
- The
StateFuturethat will return mapping iterator corresponding to the current input.
-
asyncKeys
StateFuture<StateIterator<UK>> asyncKeys()
Returns the current iterator for all the keys of this state asynchronously. When the state is not partitioned the returned iterator is the same for all inputs in a given operator instance. If state partitioning is applied, the iterator returned depends on the current operator input, as the operator maintains an independent state for each partition.- Returns:
- The
StateFuturethat will return key iterator corresponding to the current input.
-
asyncValues
StateFuture<StateIterator<UV>> asyncValues()
Returns the current iterator for all the values of this state asynchronously. When the state is not partitioned the returned iterator is the same for all inputs in a given operator instance. If state partitioning is applied, the iterator returned depends on the current operator input, as the operator maintains an independent state for each partition.- Returns:
- The
StateFuturethat will return value iterator corresponding to the current input.
-
asyncIsEmpty
StateFuture<Boolean> asyncIsEmpty()
Returns whether this state contains no key-value mappings asynchronously. When the state is not partitioned the returned value is the same for all inputs in a given operator instance. If state partitioning is applied, the value returned depends on the current operator input, as the operator maintains an independent state for each partition.- Returns:
- The
StateFuturethat will return true if there is no key-value mapping, otherwise false.
-
get
UV get(UK key)
Returns the current value associated with the given key.- Parameters:
key- The key of the mapping- Returns:
- The value of the mapping with the given key
-
put
void put(UK key, UV value)
Associates a new value with the given key.- Parameters:
key- The key of the mappingvalue- The new value of the mapping
-
putAll
void putAll(Map<UK,UV> map)
Copies all of the mappings from the given map into the state.- Parameters:
map- The mappings to be stored in this state
-
remove
void remove(UK key)
Deletes the mapping of the given key.- Parameters:
key- The key of the mapping
-
contains
boolean contains(UK key)
Returns whether there exists the given mapping.- Parameters:
key- The key of the mapping- Returns:
- True if there exists a mapping whose key equals to the given key
-
entries
Iterable<Map.Entry<UK,UV>> entries()
Returns all the mappings in the state.- Returns:
- An iterable view of all the key-value pairs in the state.
-
keys
Iterable<UK> keys()
Returns all the keys in the state.- Returns:
- An iterable view of all the keys in the state.
-
values
Iterable<UV> values()
Returns all the values in the state.- Returns:
- An iterable view of all the values in the state.
-
iterator
Iterator<Map.Entry<UK,UV>> iterator()
Iterates over all the mappings in the state.- Returns:
- An iterator over all the mappings in the state
-
isEmpty
boolean isEmpty()
Returns true if this state contains no key-value mappings, otherwise false.- Returns:
- True if this state contains no key-value mappings, otherwise false.
-
-