Java Code Examples for org.apache.flink.api.java.operators.GroupReduceOperator#setCombinable()
The following examples show how to use
org.apache.flink.api.java.operators.GroupReduceOperator#setCombinable() .
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: GroupReduceCompilationTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testAllReduceWithCombiner() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Long> data = env.generateSequence(1, 8000000).name("source"); GroupReduceOperator<Long, Long> reduced = data.reduceGroup(new CombineReducer2()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Long>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // check wiring assertEquals(sourceNode, combineNode.getInput().getSource()); assertEquals(reduceNode, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.ALL_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.ALL_GROUP_REDUCE_COMBINE, combineNode.getDriverStrategy()); // check parallelism assertEquals(8, sourceNode.getParallelism()); assertEquals(8, combineNode.getParallelism()); assertEquals(1, reduceNode.getParallelism()); assertEquals(1, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 2
Source File: GroupReduceCompilationTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testGroupedReduceWithFieldPositionKeyCombinable() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Tuple2<String, Double>> data = env.readCsvFile("file:///will/never/be/read").types(String.class, Double.class) .name("source").setParallelism(6); GroupReduceOperator<Tuple2<String, Double>, Tuple2<String, Double>> reduced = data .groupBy(1) .reduceGroup(new CombineReducer()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Tuple2<String, Double>>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // check wiring assertEquals(sourceNode, combineNode.getInput().getSource()); assertEquals(reduceNode, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.SORTED_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.SORTED_GROUP_COMBINE, combineNode.getDriverStrategy()); // check the keys assertEquals(new FieldList(1), reduceNode.getKeys(0)); assertEquals(new FieldList(1), combineNode.getKeys(0)); assertEquals(new FieldList(1), combineNode.getKeys(1)); assertEquals(new FieldList(1), reduceNode.getInput().getLocalStrategyKeys()); // check parallelism assertEquals(6, sourceNode.getParallelism()); assertEquals(6, combineNode.getParallelism()); assertEquals(8, reduceNode.getParallelism()); assertEquals(8, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 3
Source File: GroupReduceCompilationTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testGroupedReduceWithSelectorFunctionKeyCombinable() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Tuple2<String, Double>> data = env.readCsvFile("file:///will/never/be/read").types(String.class, Double.class) .name("source").setParallelism(6); GroupReduceOperator<Tuple2<String, Double>, Tuple2<String, Double>> reduced = data .groupBy(new KeySelector<Tuple2<String,Double>, String>() { public String getKey(Tuple2<String, Double> value) { return value.f0; } }) .reduceGroup(new CombineReducer()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Tuple2<String, Double>>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // get the key extractors and projectors SingleInputPlanNode keyExtractor = (SingleInputPlanNode) combineNode.getInput().getSource(); SingleInputPlanNode keyProjector = (SingleInputPlanNode) sinkNode.getInput().getSource(); // check wiring assertEquals(sourceNode, keyExtractor.getInput().getSource()); assertEquals(keyProjector, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.SORTED_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.SORTED_GROUP_COMBINE, combineNode.getDriverStrategy()); // check the keys assertEquals(new FieldList(0), reduceNode.getKeys(0)); assertEquals(new FieldList(0), combineNode.getKeys(0)); assertEquals(new FieldList(0), combineNode.getKeys(1)); assertEquals(new FieldList(0), reduceNode.getInput().getLocalStrategyKeys()); // check parallelism assertEquals(6, sourceNode.getParallelism()); assertEquals(6, keyExtractor.getParallelism()); assertEquals(6, combineNode.getParallelism()); assertEquals(8, reduceNode.getParallelism()); assertEquals(8, keyProjector.getParallelism()); assertEquals(8, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 4
Source File: GroupReduceCompilationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testAllReduceWithCombiner() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Long> data = env.generateSequence(1, 8000000).name("source"); GroupReduceOperator<Long, Long> reduced = data.reduceGroup(new CombineReducer2()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Long>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // check wiring assertEquals(sourceNode, combineNode.getInput().getSource()); assertEquals(reduceNode, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.ALL_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.ALL_GROUP_REDUCE_COMBINE, combineNode.getDriverStrategy()); // check parallelism assertEquals(8, sourceNode.getParallelism()); assertEquals(8, combineNode.getParallelism()); assertEquals(1, reduceNode.getParallelism()); assertEquals(1, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 5
Source File: GroupReduceCompilationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testGroupedReduceWithFieldPositionKeyCombinable() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Tuple2<String, Double>> data = env.readCsvFile("file:///will/never/be/read").types(String.class, Double.class) .name("source").setParallelism(6); GroupReduceOperator<Tuple2<String, Double>, Tuple2<String, Double>> reduced = data .groupBy(1) .reduceGroup(new CombineReducer()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Tuple2<String, Double>>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // check wiring assertEquals(sourceNode, combineNode.getInput().getSource()); assertEquals(reduceNode, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.SORTED_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.SORTED_GROUP_COMBINE, combineNode.getDriverStrategy()); // check the keys assertEquals(new FieldList(1), reduceNode.getKeys(0)); assertEquals(new FieldList(1), combineNode.getKeys(0)); assertEquals(new FieldList(1), combineNode.getKeys(1)); assertEquals(new FieldList(1), reduceNode.getInput().getLocalStrategyKeys()); // check parallelism assertEquals(6, sourceNode.getParallelism()); assertEquals(6, combineNode.getParallelism()); assertEquals(8, reduceNode.getParallelism()); assertEquals(8, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 6
Source File: GroupReduceCompilationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testGroupedReduceWithSelectorFunctionKeyCombinable() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Tuple2<String, Double>> data = env.readCsvFile("file:///will/never/be/read").types(String.class, Double.class) .name("source").setParallelism(6); GroupReduceOperator<Tuple2<String, Double>, Tuple2<String, Double>> reduced = data .groupBy(new KeySelector<Tuple2<String,Double>, String>() { public String getKey(Tuple2<String, Double> value) { return value.f0; } }) .reduceGroup(new CombineReducer()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Tuple2<String, Double>>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // get the key extractors and projectors SingleInputPlanNode keyExtractor = (SingleInputPlanNode) combineNode.getInput().getSource(); SingleInputPlanNode keyProjector = (SingleInputPlanNode) sinkNode.getInput().getSource(); // check wiring assertEquals(sourceNode, keyExtractor.getInput().getSource()); assertEquals(keyProjector, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.SORTED_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.SORTED_GROUP_COMBINE, combineNode.getDriverStrategy()); // check the keys assertEquals(new FieldList(0), reduceNode.getKeys(0)); assertEquals(new FieldList(0), combineNode.getKeys(0)); assertEquals(new FieldList(0), combineNode.getKeys(1)); assertEquals(new FieldList(0), reduceNode.getInput().getLocalStrategyKeys()); // check parallelism assertEquals(6, sourceNode.getParallelism()); assertEquals(6, keyExtractor.getParallelism()); assertEquals(6, combineNode.getParallelism()); assertEquals(8, reduceNode.getParallelism()); assertEquals(8, keyProjector.getParallelism()); assertEquals(8, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 7
Source File: GroupReduceCompilationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testAllReduceWithCombiner() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Long> data = env.generateSequence(1, 8000000).name("source"); GroupReduceOperator<Long, Long> reduced = data.reduceGroup(new CombineReducer2()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Long>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // check wiring assertEquals(sourceNode, combineNode.getInput().getSource()); assertEquals(reduceNode, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.ALL_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.ALL_GROUP_REDUCE_COMBINE, combineNode.getDriverStrategy()); // check parallelism assertEquals(8, sourceNode.getParallelism()); assertEquals(8, combineNode.getParallelism()); assertEquals(1, reduceNode.getParallelism()); assertEquals(1, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 8
Source File: GroupReduceCompilationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testGroupedReduceWithFieldPositionKeyCombinable() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Tuple2<String, Double>> data = env.readCsvFile("file:///will/never/be/read").types(String.class, Double.class) .name("source").setParallelism(6); GroupReduceOperator<Tuple2<String, Double>, Tuple2<String, Double>> reduced = data .groupBy(1) .reduceGroup(new CombineReducer()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Tuple2<String, Double>>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // check wiring assertEquals(sourceNode, combineNode.getInput().getSource()); assertEquals(reduceNode, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.SORTED_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.SORTED_GROUP_COMBINE, combineNode.getDriverStrategy()); // check the keys assertEquals(new FieldList(1), reduceNode.getKeys(0)); assertEquals(new FieldList(1), combineNode.getKeys(0)); assertEquals(new FieldList(1), combineNode.getKeys(1)); assertEquals(new FieldList(1), reduceNode.getInput().getLocalStrategyKeys()); // check parallelism assertEquals(6, sourceNode.getParallelism()); assertEquals(6, combineNode.getParallelism()); assertEquals(8, reduceNode.getParallelism()); assertEquals(8, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }
Example 9
Source File: GroupReduceCompilationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testGroupedReduceWithSelectorFunctionKeyCombinable() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(8); DataSet<Tuple2<String, Double>> data = env.readCsvFile("file:///will/never/be/read").types(String.class, Double.class) .name("source").setParallelism(6); GroupReduceOperator<Tuple2<String, Double>, Tuple2<String, Double>> reduced = data .groupBy(new KeySelector<Tuple2<String,Double>, String>() { public String getKey(Tuple2<String, Double> value) { return value.f0; } }) .reduceGroup(new CombineReducer()).name("reducer"); reduced.setCombinable(true); reduced.output(new DiscardingOutputFormat<Tuple2<String, Double>>()).name("sink"); Plan p = env.createProgramPlan(); OptimizedPlan op = compileNoStats(p); OptimizerPlanNodeResolver resolver = getOptimizerPlanNodeResolver(op); // get the original nodes SourcePlanNode sourceNode = resolver.getNode("source"); SingleInputPlanNode reduceNode = resolver.getNode("reducer"); SinkPlanNode sinkNode = resolver.getNode("sink"); // get the combiner SingleInputPlanNode combineNode = (SingleInputPlanNode) reduceNode.getInput().getSource(); // get the key extractors and projectors SingleInputPlanNode keyExtractor = (SingleInputPlanNode) combineNode.getInput().getSource(); SingleInputPlanNode keyProjector = (SingleInputPlanNode) sinkNode.getInput().getSource(); // check wiring assertEquals(sourceNode, keyExtractor.getInput().getSource()); assertEquals(keyProjector, sinkNode.getInput().getSource()); // check that both reduce and combiner have the same strategy assertEquals(DriverStrategy.SORTED_GROUP_REDUCE, reduceNode.getDriverStrategy()); assertEquals(DriverStrategy.SORTED_GROUP_COMBINE, combineNode.getDriverStrategy()); // check the keys assertEquals(new FieldList(0), reduceNode.getKeys(0)); assertEquals(new FieldList(0), combineNode.getKeys(0)); assertEquals(new FieldList(0), combineNode.getKeys(1)); assertEquals(new FieldList(0), reduceNode.getInput().getLocalStrategyKeys()); // check parallelism assertEquals(6, sourceNode.getParallelism()); assertEquals(6, keyExtractor.getParallelism()); assertEquals(6, combineNode.getParallelism()); assertEquals(8, reduceNode.getParallelism()); assertEquals(8, keyProjector.getParallelism()); assertEquals(8, sinkNode.getParallelism()); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail(e.getClass().getSimpleName() + " in test: " + e.getMessage()); } }