/*
* 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 T3T5FlatJoin());
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 T3T5FlatJoin());
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 T3T5FlatJoin());
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 T3T5FlatJoin());
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" +
"2,2,Hello world,2,1,Hello\n" +
"2,2,Hello world,2,2,Hello world\n";
}
case 14: {
/*
* UDF Join on tuples with tuple-returning key selectors
*/
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(new KeySelector<Tuple3<Integer,Long,String>, Tuple2<Integer, Long>>() {
private static final long serialVersionUID = 1L;
@Override
public Tuple2<Integer, Long> getKey(Tuple3<Integer,Long,String> t) {
return new Tuple2<Integer, Long>(t.f0, t.f1);
}
})
.equalTo(new KeySelector<Tuple5<Integer,Long,Integer,String,Long>, Tuple2<Integer, Long>>() {
private static final long serialVersionUID = 1L;
@Override
public Tuple2<Integer, Long> getKey(Tuple5<Integer,Long,Integer,String,Long> t) {
return new Tuple2<Integer, Long>(t.f0, t.f4);
}
})
.with(new T3T5FlatJoin());
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";
}
/**
* Joins with POJOs
*/
case 15: {
/*
* Join nested pojo against tuple (selected using a string)
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long> >> joinDs =
ds1.join(ds2).where("nestedPojo.longNumber").equalTo("f6");
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";
}
case 16: {
/*
* Join nested pojo against tuple (selected as an integer)
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long> >> joinDs =
ds1.join(ds2).where("nestedPojo.longNumber").equalTo(6); // <--- difference!
joinDs.writeAsCsv(resultPath);
env.execute();
// return expected result
return "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";
}
case 17: {
/*
* selecting multiple fields using expression language
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long> >> joinDs =
ds1.join(ds2).where("nestedPojo.longNumber", "number", "str").equalTo("f6","f0","f1");
joinDs.writeAsCsv(resultPath);
env.setDegreeOfParallelism(1);
env.execute();
// return expected result
return "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";
}
case 18: {
/*
* nested into tuple
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long> >> joinDs =
ds1.join(ds2).where("nestedPojo.longNumber", "number","nestedTupleWithCustom.f0").equalTo("f6","f0","f2");
joinDs.writeAsCsv(resultPath);
env.setDegreeOfParallelism(1);
env.execute();
// return expected result
return "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";
}
case 19: {
/*
* nested into tuple into pojo
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
DataSet<Tuple7<Integer, String, Integer, Integer, Long, String, Long>> ds2 = CollectionDataSets.getSmallTuplebasedDataSet(env);
DataSet<Tuple2<POJO, Tuple7<Integer, String, Integer, Integer, Long, String, Long> >> joinDs =
ds1.join(ds2).where("nestedTupleWithCustom.f0","nestedTupleWithCustom.f1.myInt","nestedTupleWithCustom.f1.myLong").equalTo("f2","f3","f4");
joinDs.writeAsCsv(resultPath);
env.setDegreeOfParallelism(1);
env.execute();
// return expected result
return "1 First (10,100,1000,One) 10000,(1,First,10,100,1000,One,10000)\n" +
"2 Second (20,200,2000,Two) 20000,(2,Second,20,200,2000,Two,20000)\n" +
"3 Third (30,300,3000,Three) 30000,(3,Third,30,300,3000,Three,30000)\n";
}
case 20: {
/*
* Non-POJO test to verify that full-tuple keys are working.
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds1 = CollectionDataSets.getSmallNestedTupleDataSet(env);
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds2 = CollectionDataSets.getSmallNestedTupleDataSet(env);
DataSet<Tuple2<Tuple2<Tuple2<Integer, Integer>, String>, Tuple2<Tuple2<Integer, Integer>, String> >> joinDs =
ds1.join(ds2).where(0).equalTo("f0.f0", "f0.f1"); // key is now Tuple2<Integer, Integer>
joinDs.writeAsCsv(resultPath);
env.setDegreeOfParallelism(1);
env.execute();
// return expected result
return "((1,1),one),((1,1),one)\n" +
"((2,2),two),((2,2),two)\n" +
"((3,3),three),((3,3),three)\n";
}
case 21: {
/*
* Non-POJO test to verify "nested" tuple-element selection.
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds1 = CollectionDataSets.getSmallNestedTupleDataSet(env);
DataSet<Tuple2<Tuple2<Integer, Integer>, String>> ds2 = CollectionDataSets.getSmallNestedTupleDataSet(env);
DataSet<Tuple2<Tuple2<Tuple2<Integer, Integer>, String>, Tuple2<Tuple2<Integer, Integer>, String> >> joinDs =
ds1.join(ds2).where("f0.f0").equalTo("f0.f0"); // key is now Integer from Tuple2<Integer, Integer>
joinDs.writeAsCsv(resultPath);
env.setDegreeOfParallelism(1);
env.execute();
// return expected result
return "((1,1),one),((1,1),one)\n" +
"((2,2),two),((2,2),two)\n" +
"((3,3),three),((3,3),three)\n";
}
case 22: {
/*
* full pojo with full tuple
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<POJO> ds1 = CollectionDataSets.getSmallPojoDataSet(env);
DataSet<Tuple7<Long, Integer, Integer, Long, String, Integer, String>> ds2 = CollectionDataSets.getSmallTuplebasedDataSetMatchingPojo(env);
DataSet<Tuple2<POJO, Tuple7<Long, Integer, Integer, Long, String, Integer, String> >> joinDs =
ds1.join(ds2).where("*").equalTo("*");
joinDs.writeAsCsv(resultPath);
env.setDegreeOfParallelism(1);
env.execute();
// return expected result
return "1 First (10,100,1000,One) 10000,(10000,10,100,1000,One,1,First)\n"+
"2 Second (20,200,2000,Two) 20000,(20000,20,200,2000,Two,2,Second)\n"+
"3 Third (30,300,3000,Three) 30000,(30000,30,300,3000,Three,3,Third)\n";