Search in sources :

Example 46 with MapStateDescriptor

use of org.apache.flink.api.common.state.MapStateDescriptor in project flink by apache.

the class ProcTimeRangeBoundedPrecedingFunction method open.

@Override
public void open(Configuration parameters) throws Exception {
    function = genAggsHandler.newInstance(getRuntimeContext().getUserCodeClassLoader());
    function.open(new PerKeyStateDataViewStore(getRuntimeContext()));
    output = new JoinedRowData();
    // input element are all binary row as they are came from network
    InternalTypeInfo<RowData> inputType = InternalTypeInfo.ofFields(inputFieldTypes);
    // we keep the elements received in a map state indexed based on their ingestion time
    ListTypeInfo<RowData> rowListTypeInfo = new ListTypeInfo<>(inputType);
    MapStateDescriptor<Long, List<RowData>> mapStateDescriptor = new MapStateDescriptor<>("inputState", BasicTypeInfo.LONG_TYPE_INFO, rowListTypeInfo);
    inputState = getRuntimeContext().getMapState(mapStateDescriptor);
    InternalTypeInfo<RowData> accTypeInfo = InternalTypeInfo.ofFields(accTypes);
    ValueStateDescriptor<RowData> stateDescriptor = new ValueStateDescriptor<RowData>("accState", accTypeInfo);
    accState = getRuntimeContext().getState(stateDescriptor);
    ValueStateDescriptor<Long> cleanupTsStateDescriptor = new ValueStateDescriptor<>("cleanupTsState", Types.LONG);
    this.cleanupTsState = getRuntimeContext().getState(cleanupTsStateDescriptor);
}
Also used : MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) ListTypeInfo(org.apache.flink.api.java.typeutils.ListTypeInfo) ArrayList(java.util.ArrayList) List(java.util.List) PerKeyStateDataViewStore(org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)

Example 47 with MapStateDescriptor

use of org.apache.flink.api.common.state.MapStateDescriptor in project flink by apache.

the class TimeIntervalJoin method open.

@Override
public void open(Configuration parameters) throws Exception {
    joinFunction.setRuntimeContext(getRuntimeContext());
    joinFunction.open(parameters);
    joinCollector = new EmitAwareCollector();
    // Initialize the data caches.
    ListTypeInfo<Tuple2<RowData, Boolean>> leftRowListTypeInfo = new ListTypeInfo<>(new TupleTypeInfo<>(leftType, BasicTypeInfo.BOOLEAN_TYPE_INFO));
    MapStateDescriptor<Long, List<Tuple2<RowData, Boolean>>> leftMapStateDescriptor = new MapStateDescriptor<>("IntervalJoinLeftCache", BasicTypeInfo.LONG_TYPE_INFO, leftRowListTypeInfo);
    leftCache = getRuntimeContext().getMapState(leftMapStateDescriptor);
    ListTypeInfo<Tuple2<RowData, Boolean>> rightRowListTypeInfo = new ListTypeInfo<>(new TupleTypeInfo<>(rightType, BasicTypeInfo.BOOLEAN_TYPE_INFO));
    MapStateDescriptor<Long, List<Tuple2<RowData, Boolean>>> rightMapStateDescriptor = new MapStateDescriptor<>("IntervalJoinRightCache", BasicTypeInfo.LONG_TYPE_INFO, rightRowListTypeInfo);
    rightCache = getRuntimeContext().getMapState(rightMapStateDescriptor);
    // Initialize the timer states.
    ValueStateDescriptor<Long> leftValueStateDescriptor = new ValueStateDescriptor<>("IntervalJoinLeftTimerState", Long.class);
    leftTimerState = getRuntimeContext().getState(leftValueStateDescriptor);
    ValueStateDescriptor<Long> rightValueStateDescriptor = new ValueStateDescriptor<>("IntervalJoinRightTimerState", Long.class);
    rightTimerState = getRuntimeContext().getState(rightValueStateDescriptor);
    paddingUtil = new OuterJoinPaddingUtil(leftType.toRowSize(), rightType.toRowSize());
}
Also used : MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) OuterJoinPaddingUtil(org.apache.flink.table.runtime.operators.join.OuterJoinPaddingUtil) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ListTypeInfo(org.apache.flink.api.java.typeutils.ListTypeInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)47 Test (org.junit.Test)28 List (java.util.List)15 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)14 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)13 ArrayList (java.util.ArrayList)12 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)12 HashMap (java.util.HashMap)9 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)9 Map (java.util.Map)8 Configuration (org.apache.flink.configuration.Configuration)8 BlockerCheckpointStreamFactory (org.apache.flink.runtime.util.BlockerCheckpointStreamFactory)8 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 MapState (org.apache.flink.api.common.state.MapState)6 RowData (org.apache.flink.table.data.RowData)6 Collector (org.apache.flink.util.Collector)6 ListTypeInfo (org.apache.flink.api.java.typeutils.ListTypeInfo)5 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)5 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)5 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)5