Java Code Examples for org.apache.flink.api.common.operators.base.MapOperatorBase#getInput()
The following examples show how to use
org.apache.flink.api.common.operators.base.MapOperatorBase#getInput() .
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: ReduceTranslationTests.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void translateGroupedReduceWithkeyExtractor() { try { final int parallelism = 8; ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism); DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env); initialData .groupBy(new KeySelector<Tuple3<Double, StringValue, LongValue>, StringValue>() { public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) { return value.f1; } }) .reduce(new RichReduceFunction<Tuple3<Double, StringValue, LongValue>>() { public Tuple3<Double, StringValue, LongValue> reduce(Tuple3<Double, StringValue, LongValue> value1, Tuple3<Double, StringValue, LongValue> value2) { return value1; } }).setParallelism(4) .output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>()); Plan p = env.createProgramPlan(); GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next(); MapOperatorBase<?, ?, ?> keyProjector = (MapOperatorBase<?, ?, ?>) sink.getInput(); PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyProjector.getInput(); MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput(); // check the parallelisms assertEquals(1, keyExtractor.getParallelism()); assertEquals(4, reducer.getParallelism()); assertEquals(4, keyProjector.getParallelism()); // check types TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>( new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType()); assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, keyProjector.getOperatorInfo().getInputType()); assertEquals(initialData.getType(), keyProjector.getOperatorInfo().getOutputType()); // check keys assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass()); assertTrue(keyExtractor.getInput() instanceof GenericDataSourceBase<?, ?>); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test caused an error: " + e.getMessage()); } }
Example 2
Source File: DistinctTranslationTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void translateDistinctKeySelector() { try { final int parallelism = 8; ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism); DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env); initialData.distinct(new KeySelector<Tuple3<Double, StringValue, LongValue>, StringValue>() { public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) { return value.f1; } }).setParallelism(4).output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>()); Plan p = env.createProgramPlan(); GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next(); MapOperatorBase<?, ?, ?> keyRemover = (MapOperatorBase<?, ?, ?>) sink.getInput(); PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyRemover.getInput(); MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput(); // check the parallelisms assertEquals(1, keyExtractor.getParallelism()); assertEquals(4, reducer.getParallelism()); // check types TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>( new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType()); assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, keyRemover.getOperatorInfo().getInputType()); assertEquals(initialData.getType(), keyRemover.getOperatorInfo().getOutputType()); // check keys assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass()); assertTrue(keyExtractor.getInput() instanceof GenericDataSourceBase<?, ?>); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test caused an error: " + e.getMessage()); } }
Example 3
Source File: ReduceTranslationTests.java From flink with Apache License 2.0 | 4 votes |
@Test public void translateGroupedReduceWithkeyExtractor() { try { final int parallelism = 8; ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism); DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env); initialData .groupBy(new KeySelector<Tuple3<Double, StringValue, LongValue>, StringValue>() { public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) { return value.f1; } }) .reduce(new RichReduceFunction<Tuple3<Double, StringValue, LongValue>>() { public Tuple3<Double, StringValue, LongValue> reduce(Tuple3<Double, StringValue, LongValue> value1, Tuple3<Double, StringValue, LongValue> value2) { return value1; } }).setParallelism(4) .output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>()); Plan p = env.createProgramPlan(); GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next(); MapOperatorBase<?, ?, ?> keyProjector = (MapOperatorBase<?, ?, ?>) sink.getInput(); PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyProjector.getInput(); MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput(); // check the parallelisms assertEquals(1, keyExtractor.getParallelism()); assertEquals(4, reducer.getParallelism()); assertEquals(4, keyProjector.getParallelism()); // check types TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>( new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType()); assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, keyProjector.getOperatorInfo().getInputType()); assertEquals(initialData.getType(), keyProjector.getOperatorInfo().getOutputType()); // check keys assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass()); assertTrue(keyExtractor.getInput() instanceof GenericDataSourceBase<?, ?>); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test caused an error: " + e.getMessage()); } }
Example 4
Source File: DistinctTranslationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void translateDistinctKeySelector() { try { final int parallelism = 8; ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism); DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env); initialData.distinct(new KeySelector<Tuple3<Double, StringValue, LongValue>, StringValue>() { public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) { return value.f1; } }).setParallelism(4).output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>()); Plan p = env.createProgramPlan(); GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next(); MapOperatorBase<?, ?, ?> keyRemover = (MapOperatorBase<?, ?, ?>) sink.getInput(); PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyRemover.getInput(); MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput(); // check the parallelisms assertEquals(1, keyExtractor.getParallelism()); assertEquals(4, reducer.getParallelism()); // check types TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>( new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType()); assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, keyRemover.getOperatorInfo().getInputType()); assertEquals(initialData.getType(), keyRemover.getOperatorInfo().getOutputType()); // check keys assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass()); assertTrue(keyExtractor.getInput() instanceof GenericDataSourceBase<?, ?>); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test caused an error: " + e.getMessage()); } }
Example 5
Source File: ReduceTranslationTests.java From flink with Apache License 2.0 | 4 votes |
@Test public void translateGroupedReduceWithkeyExtractor() { try { final int parallelism = 8; ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism); DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env); initialData .groupBy(new KeySelector<Tuple3<Double, StringValue, LongValue>, StringValue>() { public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) { return value.f1; } }) .reduce(new RichReduceFunction<Tuple3<Double, StringValue, LongValue>>() { public Tuple3<Double, StringValue, LongValue> reduce(Tuple3<Double, StringValue, LongValue> value1, Tuple3<Double, StringValue, LongValue> value2) { return value1; } }).setParallelism(4) .output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>()); Plan p = env.createProgramPlan(); GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next(); MapOperatorBase<?, ?, ?> keyProjector = (MapOperatorBase<?, ?, ?>) sink.getInput(); PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyProjector.getInput(); MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput(); // check the parallelisms assertEquals(1, keyExtractor.getParallelism()); assertEquals(4, reducer.getParallelism()); assertEquals(4, keyProjector.getParallelism()); // check types TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>( new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType()); assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, keyProjector.getOperatorInfo().getInputType()); assertEquals(initialData.getType(), keyProjector.getOperatorInfo().getOutputType()); // check keys assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass()); assertTrue(keyExtractor.getInput() instanceof GenericDataSourceBase<?, ?>); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test caused an error: " + e.getMessage()); } }
Example 6
Source File: DistinctTranslationTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void translateDistinctKeySelector() { try { final int parallelism = 8; ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism); DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env); initialData.distinct(new KeySelector<Tuple3<Double, StringValue, LongValue>, StringValue>() { public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) { return value.f1; } }).setParallelism(4).output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>()); Plan p = env.createProgramPlan(); GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next(); MapOperatorBase<?, ?, ?> keyRemover = (MapOperatorBase<?, ?, ?>) sink.getInput(); PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyRemover.getInput(); MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput(); // check the parallelisms assertEquals(1, keyExtractor.getParallelism()); assertEquals(4, reducer.getParallelism()); // check types TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>( new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType()); assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType()); assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType()); assertEquals(keyValueInfo, keyRemover.getOperatorInfo().getInputType()); assertEquals(initialData.getType(), keyRemover.getOperatorInfo().getOutputType()); // check keys assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass()); assertTrue(keyExtractor.getInput() instanceof GenericDataSourceBase<?, ?>); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test caused an error: " + e.getMessage()); } }