use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class WindowReaderTest method testSessionWindow.
@Test
public void testSessionWindow() throws Exception {
WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(EventTimeSessionWindows.withGap(Time.milliseconds(3))).reduce(new ReduceSum()));
OperatorState operatorState = getOperatorState(operator);
KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.reduce(new ReduceSum(), new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
List<Integer> list = readState(format);
Assert.assertEquals(Collections.singletonList(2), list);
}
use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class WindowReaderTest method getOperatorState.
private static OperatorState getOperatorState(WindowOperator<Integer, Integer, ?, Void, ?> operator) throws Exception {
KeyedOneInputStreamOperatorTestHarness<Integer, Integer, Void> harness = new KeyedOneInputStreamOperatorTestHarness<>(operator, new IdentityKeySelector<>(), Types.INT, MAX_PARALLELISM, 1, 0);
harness.open();
harness.processElement(1, 0);
harness.processElement(1, 1);
OperatorSubtaskState state = harness.snapshot(0, 0L);
harness.close();
OperatorID operatorID = OperatorIDGenerator.fromUid(UID);
OperatorState operatorState = new OperatorState(operatorID, 1, MAX_PARALLELISM);
operatorState.putState(0, state);
return operatorState;
}
use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class SavepointOutputFormatTest method createSavepoint.
private CheckpointMetadata createSavepoint() {
OperatorState operatorState = new OperatorState(OperatorIDGenerator.fromUid("uid"), 1, 128);
operatorState.putState(0, OperatorSubtaskState.builder().build());
return new CheckpointMetadata(0, Collections.singleton(operatorState), Collections.emptyList());
}
use of org.apache.flink.runtime.checkpoint.OperatorState 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);
}
use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class SavepointReader method readKeyedState.
/**
* Read keyed state from an operator in a {@code Savepoint}.
*
* @param uid The uid of the operator.
* @param function The {@link KeyedStateReaderFunction} that is called for each key in state.
* @param keyTypeInfo The type information of the key in state.
* @param outTypeInfo The type information of the output of the transform reader function.
* @param <K> The type of the key in state.
* @param <OUT> The output type of the transform function.
* @return A {@code DataStream} of objects read from keyed state.
* @throws IOException If the savepoint does not contain operator state with the given uid.
*/
public <K, OUT> DataStream<OUT> readKeyedState(String uid, KeyedStateReaderFunction<K, OUT> function, TypeInformation<K> keyTypeInfo, TypeInformation<OUT> outTypeInfo) throws IOException {
OperatorState operatorState = metadata.getOperatorState(uid);
KeyedStateInputFormat<K, VoidNamespace, OUT> inputFormat = new KeyedStateInputFormat<>(operatorState, stateBackend, MutableConfig.of(env.getConfiguration()), new KeyedStateReaderOperator<>(function, keyTypeInfo));
return SourceBuilder.fromFormat(env, inputFormat, outTypeInfo);
}
Aggregations