Search in sources :

Example 1 with POJO

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

the class PartitionITCase method testHashPartitionWithKeyExpression.

@Test
public void testHashPartitionWithKeyExpression() throws Exception {
    /*
		 * Test hash partition with key expression
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(3);
    DataSet<POJO> ds = CollectionDataSets.getDuplicatePojoDataSet(env);
    DataSet<Long> uniqLongs = ds.partitionByHash("nestedPojo.longNumber").setParallelism(4).mapPartition(new UniqueNestedPojoLongMapper());
    List<Long> result = uniqLongs.collect();
    String expected = "10000\n" + "20000\n" + "30000\n";
    compareResultAsText(result, expected);
}
Also used : POJO(org.apache.flink.test.javaApiOperators.util.CollectionDataSets.POJO) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Test(org.junit.Test)

Example 2 with POJO

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

the class SortPartitionITCase method testSortPartitionPojoByNestedFieldExpression.

@Test
public void testSortPartitionPojoByNestedFieldExpression() throws Exception {
    /*
		 * Test sort partition on field expression
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(3);
    DataSet<POJO> ds = CollectionDataSets.getMixedPojoDataSet(env);
    List<Tuple1<Boolean>> result = ds.map(new IdMapper<POJO>()).setParallelism(// parallelize input
    1).sortPartition("nestedTupleWithCustom.f1.myString", Order.ASCENDING).sortPartition("number", Order.DESCENDING).mapPartition(new OrderCheckMapper<>(new PojoChecker())).distinct().collect();
    String expected = "(true)\n";
    compareResultAsText(result, expected);
}
Also used : POJO(org.apache.flink.test.javaApiOperators.util.CollectionDataSets.POJO) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Test(org.junit.Test)

Example 3 with POJO

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

the class CoGroupITCase method testCoGroupFieldSelectorAndComplicatedKeySelector.

@Test
public void testCoGroupFieldSelectorAndComplicatedKeySelector() throws Exception {
    /*
		 * CoGroup field-selector (expression keys) + key selector function
		 * The key selector is unnecessary complicated (Tuple1) ;)
		 */
    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 KeySelector6()).equalTo(6).with(new CoGroup3());
    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 4 with POJO

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

the class CoGroupITCase method testCoGroupOnTwoCustomTypeInputsWithExpressionKeyAndFieldSelector.

@Test
public void testCoGroupOnTwoCustomTypeInputsWithExpressionKeyAndFieldSelector() throws Exception {
    /*
		 * CoGroup on two custom type inputs using expression keys
		 */
    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("nestedPojo.longNumber").equalTo(6).with(new CoGroup1());
    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 5 with POJO

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

the class DistinctITCase method testDistinctOnFullPojo.

@Test
public void testDistinctOnFullPojo() throws Exception {
    /*
		 * distinct on full Pojo
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<POJO> ds = CollectionDataSets.getDuplicatePojoDataSet(env);
    DataSet<Integer> reduceDs = ds.distinct().map(new Mapper1());
    List<Integer> result = reduceDs.collect();
    String expected = "10000\n20000\n30000\n";
    compareResultAsText(result, expected);
}
Also used : POJO(org.apache.flink.test.javaApiOperators.util.CollectionDataSets.POJO) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Test(org.junit.Test)

Aggregations

ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)20 POJO (org.apache.flink.test.javaApiOperators.util.CollectionDataSets.POJO)20 Test (org.junit.Test)20 Tuple7 (org.apache.flink.api.java.tuple.Tuple7)15 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)12 CustomType (org.apache.flink.test.javaApiOperators.util.CollectionDataSets.CustomType)3 Tuple1 (org.apache.flink.api.java.tuple.Tuple1)1