當前位置: 首頁>>代碼示例>>Java>>正文


Java MapOperatorBase.getInput方法代碼示例

本文整理匯總了Java中org.apache.flink.api.common.operators.base.MapOperatorBase.getInput方法的典型用法代碼示例。如果您正苦於以下問題:Java MapOperatorBase.getInput方法的具體用法?Java MapOperatorBase.getInput怎麽用?Java MapOperatorBase.getInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.flink.api.common.operators.base.MapOperatorBase的用法示例。


在下文中一共展示了MapOperatorBase.getInput方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: translateGroupedReduceWithkeyExtractor

import org.apache.flink.api.common.operators.base.MapOperatorBase; //導入方法依賴的package包/類
@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());
	}
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:60,代碼來源:ReduceTranslationTests.java

示例2: translateDistinctKeySelector

import org.apache.flink.api.common.operators.base.MapOperatorBase; //導入方法依賴的package包/類
@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());
	}
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:52,代碼來源:DistinctTranslationTest.java

示例3: translateGroupedReduceWithkeyExtractor

import org.apache.flink.api.common.operators.base.MapOperatorBase; //導入方法依賴的package包/類
@Test
public void translateGroupedReduceWithkeyExtractor() {
	try {
		final int DOP = 8;
		ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(DOP);
		
		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)
			.print();
		
		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 DOPs
		assertEquals(1, keyExtractor.getDegreeOfParallelism());
		assertEquals(4, reducer.getDegreeOfParallelism());
		assertEquals(4, keyProjector.getDegreeOfParallelism());
		
		// 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());
	}
}
 
開發者ID:citlab,項目名稱:vs.msc.ws14,代碼行數:61,代碼來源:ReduceTranslationTests.java


注:本文中的org.apache.flink.api.common.operators.base.MapOperatorBase.getInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。