Class LinkedMultiSetState
- java.lang.Object
-
- org.apache.flink.table.runtime.sequencedmultisetstate.linked.LinkedMultiSetState
-
- All Implemented Interfaces:
SequencedMultiSetState<org.apache.flink.table.data.RowData>
@Internal public class LinkedMultiSetState extends Object implements SequencedMultiSetState<org.apache.flink.table.data.RowData>
This class implements an ordered multi-set state backend using Flink's state primitives. It maintains the insertion order of elements and supports operations such as adding, appending, and removing elements. The state is backed by Flink's `MapState` and `ValueState` to store and manage the relationships between rows and sequence numbers (SQNs).Key features of this state implementation:
- Maintains insertion order of elements using a doubly-linked list structure.
- Supports both normal set semantics (replacing existing elements) and multi-set semantics (allowing duplicates).
- Efficiently tracks the highest sequence number and links between elements for fast traversal and updates.
- Provides methods to add, append, and remove elements with appropriate handling of state transitions.
Note: This implementation is marked as
@Internaland is intended for internal use within Flink. It may be subject to changes in future versions.Usage:
- Use the
add(RowData, long)method to add an element, replacing any existing matching element. - Use the
append(RowData, long)method to append an element, allowing duplicates. - Use the
remove(RowData)method to remove an element, with detailed removal result types.
- See Also:
SequencedMultiSetState,MapState,ValueState
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.table.runtime.sequencedmultisetstate.SequencedMultiSetState
SequencedMultiSetState.StateChangeInfo<T>, SequencedMultiSetState.StateChangeType, SequencedMultiSetState.Strategy
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SequencedMultiSetState.StateChangeInfo<org.apache.flink.table.data.RowData>add(org.apache.flink.table.data.RowData row, long timestamp)Add the given element using the normal (non-multi) set semantics: if a matching element exists already, replace it (the timestamp is updated).SequencedMultiSetState.StateChangeInfo<org.apache.flink.table.data.RowData>append(org.apache.flink.table.data.RowData row, long timestamp)Add the given element using the multi-set semantics, i.e. append.voidclear()Clear the state (in the current key context).voidclearCache()Clear caches.static LinkedMultiSetStatecreate(SequencedMultiSetStateContext p, org.apache.flink.api.common.functions.RuntimeContext ctx)booleanisEmpty()Tells whether any state exists (in the given key context).Iterator<org.apache.flink.api.java.tuple.Tuple2<org.apache.flink.table.data.RowData,Long>>iterator()Get iterator over all remaining elements and their timestamps, in order of insertion.voidloadCache()Load cache.SequencedMultiSetState.StateChangeInfo<org.apache.flink.table.data.RowData>remove(org.apache.flink.table.data.RowData row)Remove the given element.
-
-
-
Method Detail
-
create
public static LinkedMultiSetState create(SequencedMultiSetStateContext p, org.apache.flink.api.common.functions.RuntimeContext ctx)
-
add
public SequencedMultiSetState.StateChangeInfo<org.apache.flink.table.data.RowData> add(org.apache.flink.table.data.RowData row, long timestamp) throws Exception
Description copied from interface:SequencedMultiSetStateAdd the given element using the normal (non-multi) set semantics: if a matching element exists already, replace it (the timestamp is updated).- Specified by:
addin interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>- Throws:
Exception
-
append
public SequencedMultiSetState.StateChangeInfo<org.apache.flink.table.data.RowData> append(org.apache.flink.table.data.RowData row, long timestamp) throws Exception
Description copied from interface:SequencedMultiSetStateAdd the given element using the multi-set semantics, i.e. append.- Specified by:
appendin interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>- Throws:
Exception
-
remove
public SequencedMultiSetState.StateChangeInfo<org.apache.flink.table.data.RowData> remove(org.apache.flink.table.data.RowData row) throws Exception
Description copied from interface:SequencedMultiSetStateRemove the given element. If there are multiple instances of the same element, remove the first one in insertion order.- Specified by:
removein interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>- Throws:
Exception
-
clear
public void clear()
Description copied from interface:SequencedMultiSetStateClear the state (in the current key context).- Specified by:
clearin interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>
-
loadCache
public void loadCache()
Description copied from interface:SequencedMultiSetStateLoad cache.- Specified by:
loadCachein interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>
-
clearCache
public void clearCache()
Description copied from interface:SequencedMultiSetStateClear caches.- Specified by:
clearCachein interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>
-
iterator
public Iterator<org.apache.flink.api.java.tuple.Tuple2<org.apache.flink.table.data.RowData,Long>> iterator() throws Exception
Description copied from interface:SequencedMultiSetStateGet iterator over all remaining elements and their timestamps, in order of insertion.- Specified by:
iteratorin interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>- Throws:
Exception
-
isEmpty
public boolean isEmpty() throws IOExceptionDescription copied from interface:SequencedMultiSetStateTells whether any state exists (in the given key context).- Specified by:
isEmptyin interfaceSequencedMultiSetState<org.apache.flink.table.data.RowData>- Throws:
IOException
-
-