Search in sources :

Example 11 with SlidingProcessingTimeWindows

use of org.apache.flink.streaming.api.windowing.assigners.SlidingProcessingTimeWindows in project flink by apache.

the class WindowTranslationTest method testAggregateProcessingTime.

@Test
public void testAggregateProcessingTime() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setStreamTimeCharacteristic(TimeCharacteristic.ProcessingTime);
    DataStream<Tuple2<String, Integer>> source = env.fromElements(Tuple2.of("hello", 1), Tuple2.of("hello", 2));
    DataStream<Tuple2<String, Integer>> window1 = source.keyBy(new TupleKeySelector()).window(SlidingProcessingTimeWindows.of(Time.of(1, TimeUnit.SECONDS), Time.of(100, TimeUnit.MILLISECONDS))).aggregate(new DummyAggregationFunction());
    OneInputTransformation<Tuple2<String, Integer>, Tuple2<String, Integer>> transform = (OneInputTransformation<Tuple2<String, Integer>, Tuple2<String, Integer>>) window1.getTransformation();
    OneInputStreamOperator<Tuple2<String, Integer>, Tuple2<String, Integer>> operator = transform.getOperator();
    Assert.assertTrue(operator instanceof WindowOperator);
    WindowOperator<String, Tuple2<String, Integer>, ?, ?, ?> winOperator = (WindowOperator<String, Tuple2<String, Integer>, ?, ?, ?>) operator;
    Assert.assertTrue(winOperator.getTrigger() instanceof ProcessingTimeTrigger);
    Assert.assertTrue(winOperator.getWindowAssigner() instanceof SlidingProcessingTimeWindows);
    Assert.assertTrue(winOperator.getStateDescriptor() instanceof AggregatingStateDescriptor);
    processElementAndEnsureOutput(winOperator, winOperator.getKeySelector(), BasicTypeInfo.STRING_TYPE_INFO, new Tuple2<>("hello", 1));
}
Also used : AggregatingStateDescriptor(org.apache.flink.api.common.state.AggregatingStateDescriptor) ProcessingTimeTrigger(org.apache.flink.streaming.api.windowing.triggers.ProcessingTimeTrigger) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) SlidingProcessingTimeWindows(org.apache.flink.streaming.api.windowing.assigners.SlidingProcessingTimeWindows) Test(org.junit.Test)

Aggregations

SlidingProcessingTimeWindows (org.apache.flink.streaming.api.windowing.assigners.SlidingProcessingTimeWindows)11 Test (org.junit.Test)10 ProcessingTimeTrigger (org.apache.flink.streaming.api.windowing.triggers.ProcessingTimeTrigger)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)6 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)6 WindowAssigner (org.apache.flink.streaming.api.windowing.assigners.WindowAssigner)3 AggregatingStateDescriptor (org.apache.flink.api.common.state.AggregatingStateDescriptor)2 FoldingStateDescriptor (org.apache.flink.api.common.state.FoldingStateDescriptor)2 ReducingStateDescriptor (org.apache.flink.api.common.state.ReducingStateDescriptor)2 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 TumblingProcessingTimeWindows (org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows)1 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)1