Search in sources :

Example 1 with PassThroughReader

use of org.apache.flink.state.api.input.operator.window.PassThroughReader in project flink by apache.

the class WindowReaderTest method testReducingWindow.

@Test
public void testReducingWindow() throws Exception {
    WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).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(Arrays.asList(1, 1), list);
}
Also used : PassThroughReader(org.apache.flink.state.api.input.operator.window.PassThroughReader) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) ReduceSum(org.apache.flink.state.api.utils.ReduceSum) Test(org.junit.Test)

Example 2 with PassThroughReader

use of org.apache.flink.state.api.input.operator.window.PassThroughReader in project flink by apache.

the class WindowReaderTest method testProcessReader.

@Test
public void testProcessReader() throws Exception {
    WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).process(mockProcessWindowFunction(), Types.INT));
    OperatorState operatorState = getOperatorState(operator);
    KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.process(new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
    List<Integer> list = readState(format);
    Assert.assertEquals(Arrays.asList(1, 1), list);
}
Also used : PassThroughReader(org.apache.flink.state.api.input.operator.window.PassThroughReader) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) Test(org.junit.Test)

Example 3 with PassThroughReader

use of org.apache.flink.state.api.input.operator.window.PassThroughReader in project flink by apache.

the class WindowReaderTest method testAggregateWindow.

@Test
public void testAggregateWindow() throws Exception {
    WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).aggregate(new AggregateSum()));
    OperatorState operatorState = getOperatorState(operator);
    KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.aggregate(new AggregateSum(), new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
    List<Integer> list = readState(format);
    Assert.assertEquals(Arrays.asList(1, 1), list);
}
Also used : PassThroughReader(org.apache.flink.state.api.input.operator.window.PassThroughReader) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) AggregateSum(org.apache.flink.state.api.utils.AggregateSum) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Test(org.junit.Test)

Example 4 with PassThroughReader

use of org.apache.flink.state.api.input.operator.window.PassThroughReader 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);
}
Also used : PassThroughReader(org.apache.flink.state.api.input.operator.window.PassThroughReader) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) ReduceSum(org.apache.flink.state.api.utils.ReduceSum) Test(org.junit.Test)

Aggregations

Configuration (org.apache.flink.configuration.Configuration)4 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)4 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)4 PassThroughReader (org.apache.flink.state.api.input.operator.window.PassThroughReader)4 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)4 Test (org.junit.Test)4 ReduceSum (org.apache.flink.state.api.utils.ReduceSum)2 AggregateSum (org.apache.flink.state.api.utils.AggregateSum)1