Java源码示例:org.apache.flink.test.operators.util.CollectionDataSets.CrazyNested
示例1
@Test
public void testDeepNesting() throws Exception {
/*
* Deep nesting test
* + null value in pojo
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CrazyNested> ds = CollectionDataSets.getCrazyNestedDataSet(env);
DataSet<Tuple2<String, Integer>> reduceDs = ds.groupBy("nestLvl1.nestLvl2.nestLvl3.nestLvl4.f1nal")
.reduceGroup(new GroupReducer1());
List<Tuple2<String, Integer>> result = reduceDs.collect();
String expected = "aa,1\nbb,2\ncc,3\n";
compareResultAsTuples(result, expected);
}
示例2
@Test
public void testTupleContainingPojosAndRegularFields() throws Exception {
/*
* Test Tuple containing pojos and regular fields
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, CrazyNested, POJO>> ds = CollectionDataSets.getTupleContainingPojos(env);
DataSet<Integer> reduceDs = ds.groupBy("f0", "f1.*") // nested full tuple selection
.reduceGroup(new GroupReducer4());
List<Integer> result = reduceDs.collect();
String expected = "3\n1\n";
compareResultAsText(result, expected);
}
示例3
@Test
public void testDeepNesting() throws Exception {
/*
* Deep nesting test
* + null value in pojo
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CrazyNested> ds = CollectionDataSets.getCrazyNestedDataSet(env);
DataSet<Tuple2<String, Integer>> reduceDs = ds.groupBy("nestLvl1.nestLvl2.nestLvl3.nestLvl4.f1nal")
.reduceGroup(new GroupReducer1());
List<Tuple2<String, Integer>> result = reduceDs.collect();
String expected = "aa,1\nbb,2\ncc,3\n";
compareResultAsTuples(result, expected);
}
示例4
@Test
public void testTupleContainingPojosAndRegularFields() throws Exception {
/*
* Test Tuple containing pojos and regular fields
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, CrazyNested, POJO>> ds = CollectionDataSets.getTupleContainingPojos(env);
DataSet<Integer> reduceDs = ds.groupBy("f0", "f1.*") // nested full tuple selection
.reduceGroup(new GroupReducer4());
List<Integer> result = reduceDs.collect();
String expected = "3\n1\n";
compareResultAsText(result, expected);
}
示例5
@Test
public void testDeepNesting() throws Exception {
/*
* Deep nesting test
* + null value in pojo
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CrazyNested> ds = CollectionDataSets.getCrazyNestedDataSet(env);
DataSet<Tuple2<String, Integer>> reduceDs = ds.groupBy("nestLvl1.nestLvl2.nestLvl3.nestLvl4.f1nal")
.reduceGroup(new GroupReducer1());
List<Tuple2<String, Integer>> result = reduceDs.collect();
String expected = "aa,1\nbb,2\ncc,3\n";
compareResultAsTuples(result, expected);
}
示例6
@Test
public void testTupleContainingPojosAndRegularFields() throws Exception {
/*
* Test Tuple containing pojos and regular fields
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, CrazyNested, POJO>> ds = CollectionDataSets.getTupleContainingPojos(env);
DataSet<Integer> reduceDs = ds.groupBy("f0", "f1.*") // nested full tuple selection
.reduceGroup(new GroupReducer4());
List<Integer> result = reduceDs.collect();
String expected = "3\n1\n";
compareResultAsText(result, expected);
}
示例7
@Override
public void reduce(Iterable<CrazyNested> values,
Collector<Tuple2<String, Integer>> out)
throws Exception {
int c = 0; String n = null;
for (CrazyNested v : values) {
c++; // haha
n = v.nestLvl1.nestLvl2.nestLvl3.nestLvl4.f1nal;
}
out.collect(new Tuple2<>(n, c));
}
示例8
@Override
public void reduce(Iterable<CrazyNested> values,
Collector<Tuple2<String, Integer>> out)
throws Exception {
int c = 0; String n = null;
for (CrazyNested v : values) {
c++; // haha
n = v.nestLvl1.nestLvl2.nestLvl3.nestLvl4.f1nal;
}
out.collect(new Tuple2<>(n, c));
}
示例9
@Override
public void reduce(Iterable<CrazyNested> values,
Collector<Tuple2<String, Integer>> out)
throws Exception {
int c = 0; String n = null;
for (CrazyNested v : values) {
c++; // haha
n = v.nestLvl1.nestLvl2.nestLvl3.nestLvl4.f1nal;
}
out.collect(new Tuple2<>(n, c));
}
示例10
@Override
public void reduce(Iterable<Tuple3<Integer, CrazyNested, POJO>> values, Collector<Integer> out) {
out.collect(countElements(values));
}
示例11
@Override
public void reduce(Iterable<Tuple3<Integer, CrazyNested, POJO>> values, Collector<Integer> out) {
out.collect(countElements(values));
}
示例12
@Override
public void reduce(Iterable<Tuple3<Integer, CrazyNested, POJO>> values, Collector<Integer> out) {
out.collect(countElements(values));
}