Search in sources :

Example 26 with CustomType

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

the class JoinITCase method testJoinOnACustomTypeInputWithKeyExtractorAndATupleInputWithKeyFieldSelector.

@Test
public void testJoinOnACustomTypeInputWithKeyExtractorAndATupleInputWithKeyFieldSelector() 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<CustomType> ds1 = CollectionDataSets.getSmallCustomTypeDataSet(env);
    DataSet<Tuple3<Integer, Long, String>> ds2 = CollectionDataSets.get3TupleDataSet(env);
    DataSet<Tuple2<String, String>> joinDs = ds1.join(ds2).where(new KeySelector1()).equalTo(0).with(new CustT3Join());
    List<Tuple2<String, String>> result = joinDs.collect();
    String expected = "Hi,Hi\n" + "Hello,Hello\n" + "Hello world,Hello\n";
    compareResultAsTuples(result, expected);
}
Also used : CustomType(org.apache.flink.test.javaApiOperators.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 27 with CustomType

use of org.apache.flink.test.javaApiOperators.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.javaApiOperators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Test(org.junit.Test)

Aggregations

ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)27 CustomType (org.apache.flink.test.javaApiOperators.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.javaApiOperators.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