Search in sources :

Example 1 with NumberSequenceIterator

use of org.apache.flink.util.NumberSequenceIterator in project flink by apache.

the class ReplicatingDataSourceITCase method testReplicatedSourceToJoin.

@Test
public void testReplicatedSourceToJoin() throws Exception {
    /*
		 * Test replicated source going into join
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple1<Long>> source1 = env.createInput(new ReplicatingInputFormat<Long, GenericInputSplit>(new ParallelIteratorInputFormat<Long>(new NumberSequenceIterator(0l, 1000l))), BasicTypeInfo.LONG_TYPE_INFO).map(new ToTuple());
    DataSet<Tuple1<Long>> source2 = env.generateSequence(0l, 1000l).map(new ToTuple());
    DataSet<Tuple> pairs = source1.join(source2).where(0).equalTo(0).projectFirst(0).sum(0);
    List<Tuple> result = pairs.collect();
    String expectedResult = "(500500)";
    compareResultAsText(result, expectedResult);
}
Also used : ReplicatingInputFormat(org.apache.flink.api.common.io.ReplicatingInputFormat) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Tuple(org.apache.flink.api.java.tuple.Tuple) NumberSequenceIterator(org.apache.flink.util.NumberSequenceIterator) Test(org.junit.Test)

Example 2 with NumberSequenceIterator

use of org.apache.flink.util.NumberSequenceIterator in project flink by apache.

the class ReplicatingDataSourceITCase method testReplicatedSourceToCross.

@Test
public void testReplicatedSourceToCross() throws Exception {
    /*
		 * Test replicated source going into cross
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple1<Long>> source1 = env.createInput(new ReplicatingInputFormat<Long, GenericInputSplit>(new ParallelIteratorInputFormat<Long>(new NumberSequenceIterator(0l, 1000l))), BasicTypeInfo.LONG_TYPE_INFO).map(new ToTuple());
    DataSet<Tuple1<Long>> source2 = env.generateSequence(0l, 1000l).map(new ToTuple());
    DataSet<Tuple1<Long>> pairs = source1.cross(source2).filter(new FilterFunction<Tuple2<Tuple1<Long>, Tuple1<Long>>>() {

        @Override
        public boolean filter(Tuple2<Tuple1<Long>, Tuple1<Long>> value) throws Exception {
            return value.f0.f0.equals(value.f1.f0);
        }
    }).map(new MapFunction<Tuple2<Tuple1<Long>, Tuple1<Long>>, Tuple1<Long>>() {

        @Override
        public Tuple1<Long> map(Tuple2<Tuple1<Long>, Tuple1<Long>> value) throws Exception {
            return value.f0;
        }
    }).sum(0);
    List<Tuple1<Long>> result = pairs.collect();
    String expectedResult = "(500500)";
    compareResultAsText(result, expectedResult);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) MapFunction(org.apache.flink.api.common.functions.MapFunction) NumberSequenceIterator(org.apache.flink.util.NumberSequenceIterator) ReplicatingInputFormat(org.apache.flink.api.common.io.ReplicatingInputFormat) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test)

Aggregations

ReplicatingInputFormat (org.apache.flink.api.common.io.ReplicatingInputFormat)2 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)2 Tuple1 (org.apache.flink.api.java.tuple.Tuple1)2 NumberSequenceIterator (org.apache.flink.util.NumberSequenceIterator)2 Test (org.junit.Test)2 MapFunction (org.apache.flink.api.common.functions.MapFunction)1 Tuple (org.apache.flink.api.java.tuple.Tuple)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1