/*
* UDF Join on tuples with key field positions
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple2<String, String>> joinDs =
ds1.join(ds2)
.where(1)
.equalTo(1)
.with(new T3T5Join());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,Hallo\n" +
"Hello,Hallo Welt\n" +
"Hello world,Hallo Welt\n";
}
case 2: {
/*
* UDF Join on tuples with multiple key field positions
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple2<String, String>> joinDs =
ds1.join(ds2)
.where(0,1)
.equalTo(0,4)
.with(new T3T5Join());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,Hallo\n" +
"Hello,Hallo Welt\n" +
"Hello world,Hallo Welt wie gehts?\n" +
"Hello world,ABC\n" +
"I am fine.,HIJ\n" +
"I am fine.,IJK\n";
}
case 3: {
/*
* Default Join on tuples
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple2<Tuple3<Integer, Long, String>,Tuple5<Integer, Long, Integer, String, Long>>> joinDs =
ds1.join(ds2)
.where(0)
.equalTo(2);
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "(1, 1, Hi),(2, 2, 1, Hallo Welt, 2)\n" +
"(2, 2, Hello),(2, 3, 2, Hallo Welt wie, 1)\n" +
"(3, 2, Hello world),(3, 4, 3, Hallo Welt wie gehts?, 2)\n";
}
case 4: {
/*
* Join with Huge
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple2<String, String>> joinDs = ds1.joinWithHuge(ds2)
.where(1)
.equalTo(1)
.with(new T3T5Join());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,Hallo\n" +
"Hello,Hallo Welt\n" +
"Hello world,Hallo Welt\n";
}
case 5: {
/*
* Join with Tiny
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple2<String, String>> joinDs =
ds1.joinWithTiny(ds2)
.where(1)
.equalTo(1)
.with(new T3T5Join());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,Hallo\n" +
"Hello,Hallo Welt\n" +
"Hello world,Hallo Welt\n";
}
case 6: {
/*
* Join that returns the left input object
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple3<Integer, Long, String>> joinDs =
ds1.join(ds2)
.where(1)
.equalTo(1)
.with(new LeftReturningJoin());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "1,1,Hi\n" +
"2,2,Hello\n" +
"3,2,Hello world\n";
}
case 7: {
/*
* Join that returns the right input object
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> joinDs =
ds1.join(ds2)
.where(1)
.equalTo(1)
.with(new RightReturningJoin());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "1,1,0,Hallo,1\n" +
"2,2,1,Hallo Welt,2\n" +
"2,2,1,Hallo Welt,2\n";
}
case 8: {
/*
* Join with broadcast set
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Integer> intDs = CollectionDataSets.getIntegerDataSet(env);
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.getSmall5TupleDataSet(env);
DataSet<Tuple3<String, String, Integer>> joinDs =
ds1.join(ds2)
.where(1)
.equalTo(4)
.with(new T3T5BCJoin())
.withBroadcastSet(intDs, "ints");
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,Hallo,55\n" +
"Hi,Hallo Welt wie,55\n" +
"Hello,Hallo Welt,55\n" +
"Hello world,Hallo Welt,55\n";
}
case 9: {
/*
* 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.get3TupleDataSet(env);
DataSet<Tuple2<String, String>> joinDs =
ds1.join(ds2)
.where(new KeySelector<CustomType, Integer>() {
@Override
public Integer getKey(CustomType value) {
return value.myInt;
}
}
)
.equalTo(0)
.with(new CustT3Join());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,Hi\n" +
"Hello,Hello\n" +
"Hello world,Hello\n";
}
case 10: {
/*
* Project join on a tuple input 1
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple6<String, Long, String, Integer, Long, Long>> joinDs =
ds1.join(ds2)
.where(1)
.equalTo(1)
.projectFirst(2,1)
.projectSecond(3)
.projectFirst(0)
.projectSecond(4,1)
.types(String.class, Long.class, String.class, Integer.class, Long.class, Long.class);
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,1,Hallo,1,1,1\n" +
"Hello,2,Hallo Welt,2,2,2\n" +
"Hello world,2,Hallo Welt,3,2,2\n";
}
case 11: {
/*
* Project join on a tuple input 2
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
DataSet<Tuple6<String, String, Long, Long, Long, Integer>> joinDs =
ds1.join(ds2)
.where(1)
.equalTo(1)
.projectSecond(3)
.projectFirst(2,1)
.projectSecond(4,1)
.projectFirst(0)
.types(String.class, String.class, Long.class, Long.class, Long.class, Integer.class);
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hallo,Hi,1,1,1,1\n" +
"Hallo Welt,Hello,2,2,2,2\n" +
"Hallo Welt,Hello world,2,2,2,3\n";
}
case 12: {
/*
* 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 KeySelector<CustomType, Long>() {
@Override
public Long getKey(CustomType value) {
return value.myLong;
}
})
.with(new T3CustJoin());
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "Hi,Hello\n" +
"Hello,Hello world\n" +
"Hello world,Hello world\n";
}
case 13: {
/*
* (Default) Join on two custom type inputs with key extractors
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CustomType> ds1 = CollectionDataSets.getCustomTypeDataSet(env);
DataSet<CustomType> ds2 = CollectionDataSets.getSmallCustomTypeDataSet(env);
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) {
return value.myInt;
}
}
);
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "1,0,Hi,1,0,Hi\n" +
"2,1,Hello,2,1,Hello\n" +
"2,1,Hello,2,2,Hello world\n" +