Search in sources :

Example 6 with KeyedStateReaderFunction

use of org.apache.flink.state.api.functions.KeyedStateReaderFunction in project flink by apache.

the class KeyedStateInputFormatTest method testReadMultipleOutputPerKey.

@Test
public void testReadMultipleOutputPerKey() throws Exception {
    OperatorID operatorID = OperatorIDGenerator.fromUid("uid");
    OperatorSubtaskState state = createOperatorSubtaskState(new StreamFlatMap<>(new StatefulFunction()));
    OperatorState operatorState = new OperatorState(operatorID, 1, 128);
    operatorState.putState(0, state);
    KeyedStateInputFormat<?, ?, ?> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), new KeyedStateReaderOperator<>(new ReaderFunction(), Types.INT));
    KeyGroupRangeInputSplit split = format.createInputSplits(1)[0];
    KeyedStateReaderFunction<Integer, Integer> userFunction = new DoubleReaderFunction();
    List<Integer> data = readInputSplit(split, userFunction);
    Assert.assertEquals("Incorrect data read from input split", Arrays.asList(1, 1, 2, 2, 3, 3), data);
}
Also used : KeyGroupRangeInputSplit(org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit) Configuration(org.apache.flink.configuration.Configuration) KeyedStateReaderFunction(org.apache.flink.state.api.functions.KeyedStateReaderFunction) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Test(org.junit.Test)

Aggregations

KeyedStateReaderFunction (org.apache.flink.state.api.functions.KeyedStateReaderFunction)6 Configuration (org.apache.flink.configuration.Configuration)4 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)4 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)4 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)4 KeyGroupRangeInputSplit (org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit)4 Test (org.junit.Test)4 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)2 InvalidTypesException (org.apache.flink.api.common.functions.InvalidTypesException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1 RichFlatMapFunction (org.apache.flink.api.common.functions.RichFlatMapFunction)1 ValueState (org.apache.flink.api.common.state.ValueState)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1