use of org.apache.flink.api.common.aggregators.LongSumAggregator in project flink by apache.
the class AggregatorsITCase method testAggregatorWithoutParameterForIterate.
@Test
public void testAggregatorWithoutParameterForIterate() throws Exception {
/*
* Test aggregator without parameter for iterate
*/
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(parallelism);
DataSet<Integer> initialSolutionSet = CollectionDataSets.getIntegerDataSet(env);
IterativeDataSet<Integer> iteration = initialSolutionSet.iterate(MAX_ITERATIONS);
// register aggregator
LongSumAggregator aggr = new LongSumAggregator();
iteration.registerAggregator(NEGATIVE_ELEMENTS_AGGR, aggr);
// register convergence criterion
iteration.registerAggregationConvergenceCriterion(NEGATIVE_ELEMENTS_AGGR, aggr, new NegativeElementsConvergenceCriterion());
DataSet<Integer> updatedDs = iteration.map(new SubtractOneMap());
iteration.closeWith(updatedDs).writeAsText(resultPath);
env.execute();
expected = "-3\n" + "-2\n" + "-2\n" + "-1\n" + "-1\n" + "-1\n" + "0\n" + "0\n" + "0\n" + "0\n" + "1\n" + "1\n" + "1\n" + "1\n" + "1\n";
}
Aggregations