当前位置: 首页>>代码示例>>Java>>正文


Java DataSet.reduce方法代码示例

本文整理汇总了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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:ReduceITCase.java

示例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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:ReduceITCase.java

示例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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:35,代码来源:ObjectReuseITCase.java

示例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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:35,代码来源:ObjectReuseITCase.java


注:本文中的org.apache.flink.api.java.DataSet.reduce方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。