Search in sources :

Example 6 with CustomType

use of org.apache.flink.test.operators.util.CollectionDataSets.CustomType in project flink by apache.

the class CoGroupITCase method testCoGroupOnTwoCustomTypeInputsWithKeyExtractors.

@Test
public void testCoGroupOnTwoCustomTypeInputsWithKeyExtractors() throws Exception {
    /*
         * CoGroup on two custom type inputs with key extractors
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> ds2 = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> coGroupDs = ds.coGroup(ds2).where(new KeySelector4()).equalTo(new KeySelector5()).with(new CustomTypeCoGroup());
    List<CustomType> result = coGroupDs.collect();
    String expected = "1,0,test\n" + "2,6,test\n" + "3,24,test\n" + "4,60,test\n" + "5,120,test\n" + "6,210,test\n";
    compareResultAsText(result, expected);
}
Also used : CustomType(org.apache.flink.test.operators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Test(org.junit.Test)

Example 7 with CustomType

use of org.apache.flink.test.operators.util.CollectionDataSets.CustomType in project flink by apache.

the class CoGroupITCase method testCoGroupFieldSelectorAndKeySelector.

@Test
public void testCoGroupFieldSelectorAndKeySelector() throws Exception {
    /*
         * CoGroup field-selector (expression keys) + key selector function
         * The key selector is simple here
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<POJO> ds = CollectionDataSets.getSmallPojoDataSet(env);
    DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
    DataSet<CustomType> coGroupDs = ds.coGroup(ds2).where(new KeySelector1()).equalTo(6).with(new CoGroup2());
    List<CustomType> result = coGroupDs.collect();
    String expected = "-1,20000,Flink\n" + "-1,10000,Flink\n" + "-1,30000,Flink\n";
    compareResultAsText(result, expected);
}
Also used : CustomType(org.apache.flink.test.operators.util.CollectionDataSets.CustomType) POJO(org.apache.flink.test.operators.util.CollectionDataSets.POJO) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple7(org.apache.flink.api.java.tuple.Tuple7) Test(org.junit.Test)

Example 8 with CustomType

use of org.apache.flink.test.operators.util.CollectionDataSets.CustomType in project flink by apache.

the class OuterJoinITCase method testJoinWithMixedKeyTypes2.

@Test
public void testJoinWithMixedKeyTypes2() throws Exception {
    /*
         * Join on a tuple input with key field selector and a custom type input with key extractor
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
    DataSet<CustomType> ds2 = CollectionDataSets.getSmallCustomTypeDataSet(env);
    DataSet<Tuple2<String, String>> joinDs = ds1.fullOuterJoin(ds2).where(1).equalTo(new KeySelector2()).with(new T3CustJoin());
    List<Tuple2<String, String>> result = joinDs.collect();
    String expected = "null,Hi\n" + "Hi,Hello\n" + "Hello,Hello world\n" + "Hello world,Hello world\n";
    compareResultAsTuples(result, expected);
}
Also used : CustomType(org.apache.flink.test.operators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Test(org.junit.Test)

Example 9 with CustomType

use of org.apache.flink.test.operators.util.CollectionDataSets.CustomType in project flink by apache.

the class FlatMapITCase method testTypeConversionFlatMapperCustomToTuple.

@Test
public void testTypeConversionFlatMapperCustomToTuple() throws Exception {
    /*
         * Test type conversion flatmapper (Custom -> Tuple)
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<Tuple3<Integer, Long, String>> typeConversionFlatMapDs = ds.flatMap(new FlatMapper4());
    List<Tuple3<Integer, Long, String>> result = typeConversionFlatMapDs.collect();
    String expected = "1,0,Hi\n" + "2,1,Hello\n" + "2,2,Hello world\n" + "3,3,Hello world, how are you?\n" + "3,4,I am fine.\n" + "3,5,Luke Skywalker\n" + "4,6,Comment#1\n" + "4,7,Comment#2\n" + "4,8,Comment#3\n" + "4,9,Comment#4\n" + "5,10,Comment#5\n" + "5,11,Comment#6\n" + "5,12,Comment#7\n" + "5,13,Comment#8\n" + "5,14,Comment#9\n" + "6,15,Comment#10\n" + "6,16,Comment#11\n" + "6,17,Comment#12\n" + "6,18,Comment#13\n" + "6,19,Comment#14\n" + "6,20,Comment#15\n";
    compareResultAsTuples(result, expected);
}
Also used : CustomType(org.apache.flink.test.operators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Test(org.junit.Test)

Example 10 with CustomType

use of org.apache.flink.test.operators.util.CollectionDataSets.CustomType in project flink by apache.

the class JoinITCase method testDefaultJoinOnTwoCustomTypeInputsWithInnerClassKeyExtractorsClosureCleaner.

@Test
public void testDefaultJoinOnTwoCustomTypeInputsWithInnerClassKeyExtractorsClosureCleaner() throws Exception {
    /*
         * (Default) Join on two custom type inputs with key extractors, implemented as inner classes to test closure
         * cleaning
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds1 = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> ds2 = CollectionDataSets.getSmallCustomTypeDataSet(env);
    DataSet<Tuple2<CustomType, CustomType>> joinDs = ds1.join(ds2).where(new KeySelector<CustomType, Integer>() {

        @Override
        public Integer getKey(CustomType value) {
            return value.myInt;
        }
    }).equalTo(new KeySelector<CustomType, Integer>() {

        @Override
        public Integer getKey(CustomType value) throws Exception {
            return value.myInt;
        }
    });
    List<Tuple2<CustomType, CustomType>> result = joinDs.collect();
    String expected = "1,0,Hi,1,0,Hi\n" + "2,1,Hello,2,1,Hello\n" + "2,1,Hello,2,2,Hello world\n" + "2,2,Hello world,2,1,Hello\n" + "2,2,Hello world,2,2,Hello world\n";
    compareResultAsTuples(result, expected);
}
Also used : CustomType(org.apache.flink.test.operators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple2(org.apache.flink.api.java.tuple.Tuple2) KeySelector(org.apache.flink.api.java.functions.KeySelector) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)27 CustomType (org.apache.flink.test.operators.util.CollectionDataSets.CustomType)27 Test (org.junit.Test)27 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)8 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)3 Tuple7 (org.apache.flink.api.java.tuple.Tuple7)3 POJO (org.apache.flink.test.operators.util.CollectionDataSets.POJO)3 IOException (java.io.IOException)2 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)2 KeySelector (org.apache.flink.api.java.functions.KeySelector)2 Tuple1 (org.apache.flink.api.java.tuple.Tuple1)1