Iterable<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> second,
Collector<CustomType> out) throws Exception {
for(POJO p : first) {
for(Tuple7<Integer, String, Integer, Integer, Long, String, Long> t: second) {
Assert.assertTrue(p.nestedPojo.longNumber == t.f6);
out.collect(new CustomType(-1, p.nestedPojo.longNumber, "Flink"));
}
}
}
});
coGroupDs.writeAsText(resultPath);
env.execute();
// return expected result
return "-1,20000,Flink\n" +
"-1,10000,Flink\n" +
"-1,30000,Flink\n";
}
case 12: {
/*
* 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 KeySelector<POJO, Tuple1<Long>>() {
private static final long serialVersionUID = 1L;
@Override
public Tuple1<Long> getKey(POJO value)
throws Exception {
return new Tuple1<Long>(value.nestedPojo.longNumber);
}
}).equalTo(6).with(new CoGroupFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>, CustomType>() {
private static final long serialVersionUID = 1L;
@Override
public void coGroup(
Iterable<POJO> first,
Iterable<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> second,
Collector<CustomType> out) throws Exception {
for(POJO p : first) {
for(Tuple7<Integer, String, Integer, Integer, Long, String, Long> t: second) {
Assert.assertTrue(p.nestedPojo.longNumber == t.f6);
out.collect(new CustomType(-1, p.nestedPojo.longNumber, "Flink"));
}
}
}
});
coGroupDs.writeAsText(resultPath);
env.execute();
// return expected result
return "-1,20000,Flink\n" +
"-1,10000,Flink\n" +
"-1,30000,Flink\n";
}
case 13: {
/*
* 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 KeySelector<POJO, Long>() {
private static final long serialVersionUID = 1L;
@Override
public Long getKey(POJO value)
throws Exception {
return value.nestedPojo.longNumber;
}
}).equalTo(6).with(new CoGroupFunction<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long>, CustomType>() {
private static final long serialVersionUID = 1L;
@Override
public void coGroup(
Iterable<POJO> first,
Iterable<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> second,
Collector<CustomType> out) throws Exception {
for(POJO p : first) {
for(Tuple7<Integer, String, Integer, Integer, Long, String, Long> t: second) {
Assert.assertTrue(p.nestedPojo.longNumber == t.f6);
out.collect(new CustomType(-1, p.nestedPojo.longNumber, "Flink"));
}
}
}
});
coGroupDs.writeAsText(resultPath);