Java Code Examples for org.apache.flink.api.java.DataSet#reduce()
The following examples show how to use
org.apache.flink.api.java.DataSet#reduce() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReduceITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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); }
Example 2
Source File: ReduceITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: ReduceITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 4
Source File: ReduceITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 5
Source File: ReduceITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 6
Source File: ReduceITCase.java From flink with Apache License 2.0 | 6 votes |
@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); }
Example 7
Source File: ObjectReuseITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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); }
Example 8
Source File: ObjectReuseITCase.java From flink with Apache License 2.0 | 5 votes |
@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); }
Example 9
Source File: ObjectReuseITCase.java From flink with Apache License 2.0 | 5 votes |
@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); }