Search in sources :

Example 11 with CustomType

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

the class JoinITCase method testJoinOnATupleInputWithKeyFieldSelectorAndACustomTypeInputWithKeyExtractor.

@Test
public void testJoinOnATupleInputWithKeyFieldSelectorAndACustomTypeInputWithKeyExtractor() 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.getCustomTypeDataSet(env);
    DataSet<Tuple2<String, String>> joinDs = ds1.join(ds2).where(1).equalTo(new KeySelector2()).with(new T3CustJoin());
    List<Tuple2<String, String>> result = joinDs.collect();
    String expected = "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 12 with CustomType

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

the class FilterITCase method testFilterOnCustomType.

@Test
public void testFilterOnCustomType() throws Exception {
    /*
         * Test filter on custom type
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> filterDs = ds.filter(new Filter6());
    List<CustomType> result = filterDs.collect();
    String expected = "3,3,Hello world, how are you?\n" + "3,4,I am fine.\n" + "3,5,Luke Skywalker\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 13 with CustomType

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

Example 14 with CustomType

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

the class OuterJoinITCase method testJoinWithMixedKeyTypes1.

@Test
public void testJoinWithMixedKeyTypes1() 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.getSmall3TupleDataSet(env);
    DataSet<Tuple2<String, String>> joinDs = ds1.fullOuterJoin(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" + "null,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 15 with CustomType

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

the class JoinITCase method testDefaultJoinOnTwoCustomTypeInputsWithInnerClassKeyExtractorsDisabledClosureCleaner.

@Test
public void testDefaultJoinOnTwoCustomTypeInputsWithInnerClassKeyExtractorsDisabledClosureCleaner() throws Exception {
    /*
         * (Default) Join on two custom type inputs with key extractors, check if disabling closure cleaning works
         */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().disableClosureCleaner();
    DataSet<CustomType> ds1 = CollectionDataSets.getCustomTypeDataSet(env);
    DataSet<CustomType> ds2 = CollectionDataSets.getSmallCustomTypeDataSet(env);
    boolean correctExceptionTriggered = false;
    try {
        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;
            }
        });
    } catch (InvalidProgramException ex) {
        correctExceptionTriggered = (ex.getCause() instanceof java.io.NotSerializableException);
    }
    Assert.assertTrue(correctExceptionTriggered);
}
Also used : CustomType(org.apache.flink.test.operators.util.CollectionDataSets.CustomType) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) KeySelector(org.apache.flink.api.java.functions.KeySelector) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) IOException(java.io.IOException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) 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