Class SimpleVersionedListState<T>

  • Type Parameters:
    T - The type of the objects stored in the state.
    All Implemented Interfaces:
    AppendingState<T,​Iterable<T>>, ListState<T>, MergingState<T,​Iterable<T>>, State

    public class SimpleVersionedListState<T>
    extends Object
    implements ListState<T>
    A ListState that uses a SimpleVersionedSerializer instead of a TypeSerializer.

    The state wraps a ListState of type byte[], meaning it internally keeps only bytes and lazily deserializes them into objects. This has two major implications, compared to a ListState states that uses a TypeSerializer:

    • This state does not participate in >state migration. The bytes are never converted and different state versions are lazily resolved by the versioned serializer.
    • This state is generally slower than states that directly use the TypeSerializer, because of extra copies into byte arrays and extra version encodings.
    • Constructor Detail

      • SimpleVersionedListState

        public SimpleVersionedListState​(ListState<byte[]> rawState,
                                        SimpleVersionedSerializer<T> serializer)
        Creates a new SimpleVersionedListState that reads and writes bytes from the given raw ListState with the given serializer.
    • Method Detail

      • update

        public void update​(@Nullable
                           List<T> values)
                    throws Exception
        Description copied from interface: ListState
        Updates the operator state accessible by AppendingState.get() by updating existing values to the given list of values. The next time AppendingState.get() is called (for the same state partition) the returned state will represent the updated list.

        If an empty list is passed in, the state value will be null.

        Null value passed in or any null value in list is not allowed.

        Specified by:
        update in interface ListState<T>
        Parameters:
        values - The new values for the state.
        Throws:
        Exception - The method may forward exception thrown internally (by I/O or functions, or sanity check for null value).
      • addAll

        public void addAll​(@Nullable
                           List<T> values)
                    throws Exception
        Description copied from interface: ListState
        Updates the operator state accessible by AppendingState.get() by adding the given values to existing list of values. The next time AppendingState.get() is called (for the same state partition) the returned state will represent the updated list.

        If an empty list is passed in, the state value remains unchanged.

        Null value passed in or any null value in list is not allowed.

        Specified by:
        addAll in interface ListState<T>
        Parameters:
        values - The new values to be added to the state.
        Throws:
        Exception - The method may forward exception thrown internally (by I/O or functions, or sanity check for null value).
      • get

        public Iterable<T> get()
                        throws Exception
        Description copied from interface: AppendingState
        Returns the current value for the state. 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.

        NOTE TO IMPLEMENTERS: if the state is empty, then this method should return null.

        Specified by:
        get in interface AppendingState<T,​Iterable<T>>
        Returns:
        The operator state value corresponding to the current input or null if the state is empty.
        Throws:
        Exception - Thrown if the system cannot access the state.
      • add

        public void add​(T value)
                 throws Exception
        Description copied from interface: AppendingState
        Updates the operator state accessible by AppendingState.get() by adding the given value to the list of values. The next time AppendingState.get() is called (for the same state partition) the returned state will represent the updated list.

        If null is passed in, the behaviour is undefined (implementation related). TODO: An unified behaviour across all sub-classes.

        Specified by:
        add in interface AppendingState<T,​Iterable<T>>
        Parameters:
        value - The new value for the state.
        Throws:
        Exception - Thrown if the system cannot access the state.
      • clear

        public void clear()
        Description copied from interface: State
        Removes the value mapped under the current key.
        Specified by:
        clear in interface State