Search in sources :

Example 51 with Tuple4

use of org.apache.flink.api.java.tuple.Tuple4 in project flink by apache.

the class AbstractSortMergeOuterJoinIteratorITCase method computeOuterJoin.

@SuppressWarnings("unchecked, rawtypes")
private List<Tuple4<String, String, String, Object>> computeOuterJoin(ResettableMutableObjectIterator<Tuple2<String, String>> input1, ResettableMutableObjectIterator<Tuple2<String, Integer>> input2, OuterJoinType outerJoinType) throws Exception {
    input1.reset();
    input2.reset();
    AbstractMergeOuterJoinIterator iterator = createOuterJoinIterator(outerJoinType, input1, input2, serializer1, comparator1, serializer2, comparator2, pairComp, this.memoryManager, this.ioManager, PAGES_FOR_BNLJN, this.parentTask);
    List<Tuple4<String, String, String, Object>> actual = new ArrayList<>();
    ListCollector<Tuple4<String, String, String, Object>> collector = new ListCollector<>(actual);
    while (iterator.callWithNextKey(new SimpleTupleJoinFunction(), collector)) ;
    iterator.close();
    return actual;
}
Also used : Tuple4(org.apache.flink.api.java.tuple.Tuple4) SimpleTupleJoinFunction(org.apache.flink.runtime.operators.testutils.SimpleTupleJoinFunction) ListCollector(org.apache.flink.api.common.functions.util.ListCollector) ArrayList(java.util.ArrayList)

Example 52 with Tuple4

use of org.apache.flink.api.java.tuple.Tuple4 in project flink by apache.

the class EventTimeWindowCheckpointingITCase method testPreAggregatedTumblingTimeWindow.

@Test
public void testPreAggregatedTumblingTimeWindow() {
    final int numElementsPerKey = numElementsPerKey();
    final int windowSize = windowSize();
    final int numKeys = numKeys();
    try {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(PARALLELISM);
        env.enableCheckpointing(100);
        env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 0));
        env.setStateBackend(this.stateBackend);
        env.getConfig().setUseSnapshotCompression(true);
        env.addSource(new FailingSource(new KeyedEventTimeGenerator(numKeys, windowSize), numElementsPerKey)).rebalance().keyBy(0).window(TumblingEventTimeWindows.of(Time.milliseconds(windowSize))).reduce(new ReduceFunction<Tuple2<Long, IntType>>() {

            @Override
            public Tuple2<Long, IntType> reduce(Tuple2<Long, IntType> a, Tuple2<Long, IntType> b) {
                return new Tuple2<>(a.f0, new IntType(a.f1.value + b.f1.value));
            }
        }, new RichWindowFunction<Tuple2<Long, IntType>, Tuple4<Long, Long, Long, IntType>, Tuple, TimeWindow>() {

            private boolean open = false;

            @Override
            public void open(Configuration parameters) {
                assertEquals(PARALLELISM, getRuntimeContext().getNumberOfParallelSubtasks());
                open = true;
            }

            @Override
            public void apply(Tuple tuple, TimeWindow window, Iterable<Tuple2<Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) {
                // validate that the function has been opened properly
                assertTrue(open);
                for (Tuple2<Long, IntType> in : input) {
                    final Tuple4<Long, Long, Long, IntType> output = new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f1);
                    out.collect(output);
                }
            }
        }).addSink(new ValidatingSink<>(new SinkValidatorUpdateFun(numElementsPerKey), new SinkValidatorCheckFun(numKeys, numElementsPerKey, windowSize))).setParallelism(1);
        env.execute("Tumbling Window Test");
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) ValidatingSink(org.apache.flink.test.checkpointing.utils.ValidatingSink) FailingSource(org.apache.flink.test.checkpointing.utils.FailingSource) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) IOException(java.io.IOException) IntType(org.apache.flink.test.checkpointing.utils.IntType) Tuple4(org.apache.flink.api.java.tuple.Tuple4) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Tuple(org.apache.flink.api.java.tuple.Tuple) Test(org.junit.Test)

Example 53 with Tuple4

use of org.apache.flink.api.java.tuple.Tuple4 in project flink by apache.

the class EventTimeWindowCheckpointingITCase method testSlidingTimeWindow.

@Test
public void testSlidingTimeWindow() {
    final int numElementsPerKey = numElementsPerKey();
    final int windowSize = windowSize();
    final int windowSlide = windowSlide();
    final int numKeys = numKeys();
    try {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setMaxParallelism(2 * PARALLELISM);
        env.setParallelism(PARALLELISM);
        env.enableCheckpointing(100);
        env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 0));
        env.setStateBackend(this.stateBackend);
        env.getConfig().setUseSnapshotCompression(true);
        env.addSource(new FailingSource(new KeyedEventTimeGenerator(numKeys, windowSlide), numElementsPerKey)).rebalance().keyBy(0).window(SlidingEventTimeWindows.of(Time.milliseconds(windowSize), Time.milliseconds(windowSlide))).apply(new RichWindowFunction<Tuple2<Long, IntType>, Tuple4<Long, Long, Long, IntType>, Tuple, TimeWindow>() {

            private boolean open = false;

            @Override
            public void open(Configuration parameters) {
                assertEquals(PARALLELISM, getRuntimeContext().getNumberOfParallelSubtasks());
                open = true;
            }

            @Override
            public void apply(Tuple tuple, TimeWindow window, Iterable<Tuple2<Long, IntType>> values, Collector<Tuple4<Long, Long, Long, IntType>> out) {
                // validate that the function has been opened properly
                assertTrue(open);
                int sum = 0;
                long key = -1;
                for (Tuple2<Long, IntType> value : values) {
                    sum += value.f1.value;
                    key = value.f0;
                }
                final Tuple4<Long, Long, Long, IntType> output = new Tuple4<>(key, window.getStart(), window.getEnd(), new IntType(sum));
                out.collect(output);
            }
        }).addSink(new ValidatingSink<>(new SinkValidatorUpdateFun(numElementsPerKey), new SinkValidatorCheckFun(numKeys, numElementsPerKey, windowSlide))).setParallelism(1);
        env.execute("Tumbling Window Test");
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) ValidatingSink(org.apache.flink.test.checkpointing.utils.ValidatingSink) FailingSource(org.apache.flink.test.checkpointing.utils.FailingSource) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) IOException(java.io.IOException) IntType(org.apache.flink.test.checkpointing.utils.IntType) Tuple4(org.apache.flink.api.java.tuple.Tuple4) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Tuple(org.apache.flink.api.java.tuple.Tuple) Test(org.junit.Test)

Example 54 with Tuple4

use of org.apache.flink.api.java.tuple.Tuple4 in project flink by apache.

the class EventTimeAllWindowCheckpointingITCase method testTumblingTimeWindow.

// ------------------------------------------------------------------------
@Test
public void testTumblingTimeWindow() {
    final int numElementsPerKey = 3000;
    final int windowSize = 100;
    final int numKeys = 1;
    try {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(PARALLELISM);
        env.enableCheckpointing(100);
        env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 0));
        env.addSource(new FailingSource(new EventTimeWindowCheckpointingITCase.KeyedEventTimeGenerator(numKeys, windowSize), numElementsPerKey)).rebalance().windowAll(TumblingEventTimeWindows.of(Time.milliseconds(windowSize))).apply(new RichAllWindowFunction<Tuple2<Long, IntType>, Tuple4<Long, Long, Long, IntType>, TimeWindow>() {

            private boolean open = false;

            @Override
            public void open(Configuration parameters) {
                assertEquals(1, getRuntimeContext().getNumberOfParallelSubtasks());
                open = true;
            }

            @Override
            public void apply(TimeWindow window, Iterable<Tuple2<Long, IntType>> values, Collector<Tuple4<Long, Long, Long, IntType>> out) {
                // validate that the function has been opened properly
                assertTrue(open);
                int sum = 0;
                long key = -1;
                for (Tuple2<Long, IntType> value : values) {
                    sum += value.f1.value;
                    key = value.f0;
                }
                out.collect(new Tuple4<>(key, window.getStart(), window.getEnd(), new IntType(sum)));
            }
        }).addSink(new ValidatingSink<>(new EventTimeWindowCheckpointingITCase.SinkValidatorUpdateFun(numElementsPerKey), new EventTimeWindowCheckpointingITCase.SinkValidatorCheckFun(numKeys, numElementsPerKey, windowSize))).setParallelism(1);
        env.execute("Tumbling Window Test");
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) ValidatingSink(org.apache.flink.test.checkpointing.utils.ValidatingSink) FailingSource(org.apache.flink.test.checkpointing.utils.FailingSource) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) IntType(org.apache.flink.test.checkpointing.utils.IntType) Tuple4(org.apache.flink.api.java.tuple.Tuple4) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Example 55 with Tuple4

use of org.apache.flink.api.java.tuple.Tuple4 in project flink by apache.

the class EventTimeAllWindowCheckpointingITCase method testPreAggregatedSlidingTimeWindow.

@Test
public void testPreAggregatedSlidingTimeWindow() {
    final int numElementsPerKey = 3000;
    final int windowSize = 1000;
    final int windowSlide = 100;
    final int numKeys = 1;
    try {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(PARALLELISM);
        env.enableCheckpointing(100);
        env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 0));
        env.addSource(new FailingSource(new EventTimeWindowCheckpointingITCase.KeyedEventTimeGenerator(numKeys, windowSlide), numElementsPerKey)).rebalance().windowAll(SlidingEventTimeWindows.of(Time.milliseconds(windowSize), Time.milliseconds(windowSlide))).reduce(new ReduceFunction<Tuple2<Long, IntType>>() {

            @Override
            public Tuple2<Long, IntType> reduce(Tuple2<Long, IntType> a, Tuple2<Long, IntType> b) {
                return new Tuple2<>(a.f0, new IntType(a.f1.value + b.f1.value));
            }
        }, new RichAllWindowFunction<Tuple2<Long, IntType>, Tuple4<Long, Long, Long, IntType>, TimeWindow>() {

            private boolean open = false;

            @Override
            public void open(Configuration parameters) {
                assertEquals(1, getRuntimeContext().getNumberOfParallelSubtasks());
                open = true;
            }

            @Override
            public void apply(TimeWindow window, Iterable<Tuple2<Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) {
                // validate that the function has been opened properly
                assertTrue(open);
                for (Tuple2<Long, IntType> in : input) {
                    out.collect(new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f1));
                }
            }
        }).addSink(new ValidatingSink<>(new EventTimeWindowCheckpointingITCase.SinkValidatorUpdateFun(numElementsPerKey), new EventTimeWindowCheckpointingITCase.SinkValidatorCheckFun(numKeys, numElementsPerKey, windowSlide))).setParallelism(1);
        env.execute("Tumbling Window Test");
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) ValidatingSink(org.apache.flink.test.checkpointing.utils.ValidatingSink) FailingSource(org.apache.flink.test.checkpointing.utils.FailingSource) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) IntType(org.apache.flink.test.checkpointing.utils.IntType) Tuple4(org.apache.flink.api.java.tuple.Tuple4) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Aggregations

Tuple4 (org.apache.flink.api.java.tuple.Tuple4)57 Test (org.junit.Test)44 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)31 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)21 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)18 Configuration (org.apache.flink.configuration.Configuration)15 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)15 Tuple (org.apache.flink.api.java.tuple.Tuple)13 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)12 IOException (java.io.IOException)11 MiniClusterResourceConfiguration (org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration)9 FailingSource (org.apache.flink.test.checkpointing.utils.FailingSource)9 IntType (org.apache.flink.test.checkpointing.utils.IntType)9 ValidatingSink (org.apache.flink.test.checkpointing.utils.ValidatingSink)9 SuccessException (org.apache.flink.test.util.SuccessException)6 Plan (org.apache.flink.api.common.Plan)5 KeySelector (org.apache.flink.api.java.functions.KeySelector)5 ArrayList (java.util.ArrayList)3 DataSet (org.apache.flink.api.java.DataSet)3 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)3