本文整理汇总了Java中org.apache.flink.api.java.DataSet.reduce方法的典型用法代码示例。如果您正苦于以下问题:Java DataSet.reduce方法的具体用法?Java DataSet.reduce怎么用?Java DataSet.reduce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.java.DataSet
的用法示例。
在下文中一共展示了DataSet.reduce方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAllReduceForTuple
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testAllReduceForTuple() throws Exception {
/*
* All-reduce for tuple
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
DataSet<Tuple3<Integer, Long, String>> reduceDs = ds.
reduce(new AllAddingTuple3Reduce());
List<Tuple3<Integer, Long, String>> result = reduceDs.collect();
String expected = "231,91,Hello World\n";
compareResultAsTuples(result, expected);
}
示例2: testAllReduceForCustomTypes
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testAllReduceForCustomTypes() throws Exception {
/*
* All-reduce for custom types
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<CustomType> ds = CollectionDataSets.getCustomTypeDataSet(env);
DataSet<CustomType> reduceDs = ds.
reduce(new AllAddingCustomTypeReduce());
List<CustomType> result = reduceDs.collect();
String expected = "91,210,Hello!";
compareResultAsText(result, expected);
}
示例3: testGlobalReduce
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testGlobalReduce() throws Exception {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
if (objectReuse) {
env.getConfig().enableObjectReuse();
} else {
env.getConfig().disableObjectReuse();
}
DataSet<Tuple2<String, Integer>> input = env.fromCollection(REDUCE_DATA);
DataSet<Tuple2<String, Integer>> result = input.reduce(
new ReduceFunction<Tuple2<String, Integer>>() {
@Override
public Tuple2<String, Integer> reduce(
Tuple2<String, Integer> value1,
Tuple2<String, Integer> value2) {
if (value1.f1 % 3 == 0) {
value1.f1 += value2.f1;
return value1;
} else {
value2.f1 += value1.f1;
return value2;
}
}
});
Tuple2<String, Integer> res = result.collect().get(0);
assertEquals(new Tuple2<>("a", 60), res);
}
示例4: testGlobalReduce
import org.apache.flink.api.java.DataSet; //导入方法依赖的package包/类
@Test
public void testGlobalReduce() throws Exception {
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
if (objectReuse) {
env.getConfig().enableObjectReuse();
} else {
env.getConfig().disableObjectReuse();
}
DataSet<Tuple2<String, Integer>> input = env.fromCollection(REDUCE_DATA);
DataSet<Tuple2<String, Integer>> result = input.reduce(
new ReduceFunction<Tuple2<String, Integer>>() {
@Override
public Tuple2<String, Integer> reduce(
Tuple2<String, Integer> value1,
Tuple2<String, Integer> value2) {
if (value1.f1 % 3 == 0) {
value1.f1 += value2.f1;
return value1;
} else {
value2.f1 += value1.f1;
return value2;
}
}
});
Tuple2<String, Integer> res = result.collect().get(0);
assertEquals(new Tuple2<>("a", 60), res);
}