Search in sources :

Example 11 with CustomType

use of org.apache.flink.test.javaApiOperators.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.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 12 with CustomType

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

the class GroupReduceITCase method testCorrectnessOfAllGroupReduceForCustomTypes.

@Test
public void testCorrectnessOfAllGroupReduceForCustomTypes() throws Exception {
    /*
		 * check correctness of all-groupreduce for custom types
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> reduceDs = ds.reduceGroup(new AllAddingCustomTypeGroupReduce());
    List<CustomType> result = reduceDs.collect();
    String expected = "91,210,Hello!";
    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)

Example 13 with CustomType

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

the class GroupReduceITCase method testCorrectnessOfGroupReduceOnCustomTypeWithKeyExtractorAndCombine.

@Test
public void testCorrectnessOfGroupReduceOnCustomTypeWithKeyExtractorAndCombine() throws Exception {
    /*
		 * check correctness of groupReduce on custom type with key extractor and combine
		 */
    org.junit.Assume.assumeTrue(mode != TestExecutionMode.COLLECTION);
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> reduceDs = ds.groupBy(new KeySelector3()).reduceGroup(new CustomTypeGroupReduceWithCombine());
    List<CustomType> result = reduceDs.collect();
    String expected = "1,0,test1\n" + "2,3,test2\n" + "3,12,test3\n" + "4,30,test4\n" + "5,60,test5\n" + "6,105,test6\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)

Example 14 with CustomType

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

the class GroupReduceITCase method testPojoKeySelectorGroupSort.

@Test
public void testPojoKeySelectorGroupSort() throws Exception {
    /*
		 * check correctness of sorted groupReduce on custom type with keyselector sorting
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> reduceDs = ds.groupBy(new TwoTuplePojoExtractor()).sortGroup(new StringPojoExtractor(), Order.DESCENDING).reduceGroup(new CustomTypeSortedGroupReduce());
    List<CustomType> result = reduceDs.collect();
    String expected = "1,0,Hi\n" + "2,3,Hello world-Hello\n" + "3,12,Luke Skywalker-I am fine.-Hello world, how are you?\n" + "4,30,Comment#4-Comment#3-Comment#2-Comment#1\n" + "5,60,Comment#9-Comment#8-Comment#7-Comment#6-Comment#5\n" + "6,105,Comment#15-Comment#14-Comment#13-Comment#12-Comment#11-Comment#10\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)

Example 15 with CustomType

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

the class MapITCase method testTypeConversionMapperCustomToTuple.

@Test
public void testTypeConversionMapperCustomToTuple() throws Exception {
    /*
		 * Test type conversion mapper (Custom -> Tuple)
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<Tuple3<Integer, Long, String>> typeConversionMapDs = ds.map(new Mapper3());
    List<Tuple3<Integer, Long, String>> result = typeConversionMapDs.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.javaApiOperators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple3(org.apache.flink.api.java.tuple.Tuple3) 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