Search in sources :

Example 21 with CustomType

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

the class CrossITCase method testCorrectnessOfCrossOnTwoCustomTypeInputs.

@Test
public void testCorrectnessOfCrossOnTwoCustomTypeInputs() throws Exception {
    /*
		 * check correctness of cross on two custom type inputs
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getSmallCustomTypeDataSet(env);
    DataSet<CustomType> ds2 = CollectionDataSets.getSmallCustomTypeDataSet(env);
    DataSet<CustomType> crossDs = ds.cross(ds2).with(new CustomTypeCross());
    List<CustomType> result = crossDs.collect();
    String expected = "1,0,HiHi\n" + "2,1,HiHello\n" + "2,2,HiHello world\n" + "2,1,HelloHi\n" + "4,2,HelloHello\n" + "4,3,HelloHello world\n" + "2,2,Hello worldHi\n" + "4,3,Hello worldHello\n" + "4,4,Hello worldHello world";
    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 22 with CustomType

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

the class CoGroupITCase method testCoGroupTwoCustomTypeInputsWithExpressionKeys.

@Test
public void testCoGroupTwoCustomTypeInputsWithExpressionKeys() throws Exception {
    /*
		 * CoGroup on two custom type inputs using expression keys
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> ds2 = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> coGroupDs = ds.coGroup(ds2).where("myInt").equalTo("myInt").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)

Example 23 with CustomType

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

Example 24 with CustomType

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

the class GroupReduceITCase method testCorrectnessOfGroupReduceOnCustomTypeWithTypeExtractor.

@Test
public void testCorrectnessOfGroupReduceOnCustomTypeWithTypeExtractor() throws Exception {
    /*
		 * check correctness of groupReduce on custom type with type extractor
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> reduceDs = ds.groupBy(new KeySelector2()).reduceGroup(new CustomTypeGroupReduce());
    List<CustomType> result = reduceDs.collect();
    String expected = "1,0,Hello!\n" + "2,3,Hello!\n" + "3,12,Hello!\n" + "4,30,Hello!\n" + "5,60,Hello!\n" + "6,105,Hello!\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 25 with CustomType

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