Search in sources :

Example 6 with KeyGroupRangeInputSplit

use of org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit 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)

Example 7 with KeyGroupRangeInputSplit

use of org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit in project flink by apache.

the class WindowReaderTest method readState.

@Nonnull
private <OUT> List<OUT> readState(KeyedStateInputFormat<Integer, TimeWindow, OUT> format) throws IOException {
    KeyGroupRangeInputSplit split = format.createInputSplits(1)[0];
    List<OUT> data = new ArrayList<>();
    format.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
    format.openInputFormat();
    format.open(split);
    while (!format.reachedEnd()) {
        data.add(format.nextRecord(null));
    }
    format.close();
    format.closeInputFormat();
    return data;
}
Also used : KeyGroupRangeInputSplit(org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 8 with KeyGroupRangeInputSplit

use of org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit in project flink by apache.

the class KeyedStateInputFormatTest method testCreatePartitionedInputSplits.

@Test
public void testCreatePartitionedInputSplits() 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[] splits = format.createInputSplits(4);
    Assert.assertEquals("Failed to properly partition operator state into input splits", 4, splits.length);
}
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

KeyGroupRangeInputSplit (org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit)8 Configuration (org.apache.flink.configuration.Configuration)7 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)7 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)7 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)7 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)7 Test (org.junit.Test)7 KeyedStateReaderFunction (org.apache.flink.state.api.functions.KeyedStateReaderFunction)6 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 MockStreamingRuntimeContext (org.apache.flink.streaming.util.MockStreamingRuntimeContext)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Set (java.util.Set)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 Types (org.apache.flink.api.common.typeinfo.Types)1