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
    State interface 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 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 StateFuture that will return value corresponding to the current input. When no corresponding value for this key, the future will return null.
      • 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 a null value 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 StateFuture that 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 a null value 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 StateFuture that 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 StateFuture that 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 StateFuture that 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 StateFuture that 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 StateFuture that 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 StateFuture that 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 StateFuture that will return true if there is no key-value mapping, otherwise false.