Java Code Examples for org.apache.flink.runtime.operators.util.TaskConfig#setInputSerializer()

The following examples show how to use org.apache.flink.runtime.operators.util.TaskConfig#setInputSerializer() . 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: ChainedOperatorsMetricTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void addChainedOperator() {
	final TaskConfig chainedConfig = new TaskConfig(new Configuration());

	// input
	chainedConfig.addInputToGroup(0);
	chainedConfig.setInputSerializer(serFact, 0);

	// output
	chainedConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
	chainedConfig.setOutputSerializer(serFact);

	// driver
	chainedConfig.setDriverStrategy(DriverStrategy.FLAT_MAP);

	// udf
	chainedConfig.setStubWrapper(new UserCodeClassWrapper<>(DuplicatingFlatMapFunction.class));

	getTaskConfig().addChainedTask(ChainedFlatMapDriver.class, chainedConfig, CHAINED_OPERATOR_NAME);
}
 
Example 2
Source File: ChainedOperatorsMetricTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void addChainedOperator() {
	final TaskConfig chainedConfig = new TaskConfig(new Configuration());

	// input
	chainedConfig.addInputToGroup(0);
	chainedConfig.setInputSerializer(serFact, 0);

	// output
	chainedConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
	chainedConfig.setOutputSerializer(serFact);

	// driver
	chainedConfig.setDriverStrategy(DriverStrategy.FLAT_MAP);

	// udf
	chainedConfig.setStubWrapper(new UserCodeClassWrapper<>(DuplicatingFlatMapFunction.class));

	getTaskConfig().addChainedTask(ChainedFlatMapDriver.class, chainedConfig, CHAINED_OPERATOR_NAME);
}
 
Example 3
Source File: ChainedOperatorsMetricTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void addChainedOperator() {
	final TaskConfig chainedConfig = new TaskConfig(new Configuration());

	// input
	chainedConfig.addInputToGroup(0);
	chainedConfig.setInputSerializer(serFact, 0);

	// output
	chainedConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
	chainedConfig.setOutputSerializer(serFact);

	// driver
	chainedConfig.setDriverStrategy(DriverStrategy.FLAT_MAP);

	// udf
	chainedConfig.setStubWrapper(new UserCodeClassWrapper<>(DuplicatingFlatMapFunction.class));

	getTaskConfig().addChainedTask(ChainedFlatMapDriver.class, chainedConfig, CHAINED_OPERATOR_NAME);
}
 
Example 4
Source File: TaskTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public IteratorWrappingTestSingleInputGate<Record> addInput(MutableObjectIterator<Record> input, int groupId, boolean read) {
	final IteratorWrappingTestSingleInputGate<Record> reader = this.mockEnv.addInput(input);
	TaskConfig conf = new TaskConfig(this.mockEnv.getTaskConfiguration());
	conf.addInputToGroup(groupId);
	conf.setInputSerializer(RecordSerializerFactory.get(), groupId);

	if (read) {
		reader.notifyNonEmpty();
	}

	return reader;
}
 
Example 5
Source File: TaskTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
public IteratorWrappingTestSingleInputGate<Record> addInput(MutableObjectIterator<Record> input, int groupId, boolean read) {
	final IteratorWrappingTestSingleInputGate<Record> reader = this.mockEnv.addInput(input);
	TaskConfig conf = new TaskConfig(this.mockEnv.getTaskConfiguration());
	conf.addInputToGroup(groupId);
	conf.setInputSerializer(RecordSerializerFactory.get(), groupId);

	if (read) {
		reader.notifyNonEmpty();
	}

	return reader;
}
 
Example 6
Source File: TaskTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
public IteratorWrappingTestSingleInputGate<Record> addInput(MutableObjectIterator<Record> input, int groupId, boolean read) {
	final IteratorWrappingTestSingleInputGate<Record> reader = this.mockEnv.addInput(input);
	TaskConfig conf = new TaskConfig(this.mockEnv.getTaskConfiguration());
	conf.addInputToGroup(groupId);
	conf.setInputSerializer(RecordSerializerFactory.get(), groupId);

	if (read) {
		reader.notifyNonEmpty();
	}

	return reader;
}
 
Example 7
Source File: ChainedAllReduceDriverTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testMapTask() throws Exception {
	final int keyCnt = 100;
	final int valCnt = 20;

	final double memoryFraction = 1.0;

	// environment
	initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	mockEnv.getExecutionConfig().enableObjectReuse();
	addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
	addOutput(this.outList);

	// chained reduce config
	{
		final TaskConfig reduceConfig = new TaskConfig(new Configuration());

		// input
		reduceConfig.addInputToGroup(0);
		reduceConfig.setInputSerializer(serFact, 0);

		// output
		reduceConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
		reduceConfig.setOutputSerializer(serFact);

		// driver
		reduceConfig.setDriverStrategy(DriverStrategy.ALL_REDUCE);
		reduceConfig.setDriverComparator(compFact, 0);
		reduceConfig.setDriverComparator(compFact, 1);
		reduceConfig.setRelativeMemoryDriver(memoryFraction);

		// udf
		reduceConfig.setStubWrapper(new UserCodeClassWrapper<>(MockReduceStub.class));

		getTaskConfig().addChainedTask(ChainedAllReduceDriver.class, reduceConfig, "reduce");
	}

	// chained map+reduce
	{
		registerTask(FlatMapDriver.class, MockMapStub.class);
		BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);

		testTask.invoke();
	}

	int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;

	Assert.assertEquals(1, this.outList.size());
	Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
}
 
Example 8
Source File: JobGraphGenerator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private void addLocalInfoFromChannelToConfig(Channel channel, TaskConfig config, int inputNum, boolean isBroadcastChannel) {
	// serializer
	if (isBroadcastChannel) {
		config.setBroadcastInputSerializer(channel.getSerializer(), inputNum);
		
		if (channel.getLocalStrategy() != LocalStrategy.NONE || (channel.getTempMode() != null && channel.getTempMode() != TempMode.NONE)) {
			throw new CompilerException("Found local strategy or temp mode on a broadcast variable channel.");
		} else {
			return;
		}
	} else {
		config.setInputSerializer(channel.getSerializer(), inputNum);
	}
	
	// local strategy
	if (channel.getLocalStrategy() != LocalStrategy.NONE) {
		config.setInputLocalStrategy(inputNum, channel.getLocalStrategy());
		if (channel.getLocalStrategyComparator() != null) {
			config.setInputComparator(channel.getLocalStrategyComparator(), inputNum);
		}
	}
	
	assignLocalStrategyResources(channel, config, inputNum);
	
	// materialization / caching
	if (channel.getTempMode() != null) {
		final TempMode tm = channel.getTempMode();

		boolean needsMemory = false;
		// Don't add a pipeline breaker if the data exchange is already blocking, EXCEPT the channel is within an iteration.
		if (tm.breaksPipeline() &&
				(channel.isOnDynamicPath() || channel.getDataExchangeMode() != DataExchangeMode.BATCH) ) {
			config.setInputAsynchronouslyMaterialized(inputNum, true);
			needsMemory = true;
		}
		if (tm.isCached()) {
			config.setInputCached(inputNum, true);
			needsMemory = true;
		}
		
		if (needsMemory) {
			// sanity check
			if (tm == TempMode.NONE || channel.getRelativeTempMemory() <= 0) {
				throw new CompilerException("Bug in compiler: Inconsistent description of input materialization.");
			}
			config.setRelativeInputMaterializationMemory(inputNum, channel.getRelativeTempMemory());
		}
	}
}
 
Example 9
Source File: ChainedAllReduceDriverTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMapTask() throws Exception {
	final int keyCnt = 100;
	final int valCnt = 20;

	final double memoryFraction = 1.0;

	// environment
	initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	mockEnv.getExecutionConfig().enableObjectReuse();
	addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
	addOutput(this.outList);

	// chained reduce config
	{
		final TaskConfig reduceConfig = new TaskConfig(new Configuration());

		// input
		reduceConfig.addInputToGroup(0);
		reduceConfig.setInputSerializer(serFact, 0);

		// output
		reduceConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
		reduceConfig.setOutputSerializer(serFact);

		// driver
		reduceConfig.setDriverStrategy(DriverStrategy.ALL_REDUCE);
		reduceConfig.setDriverComparator(compFact, 0);
		reduceConfig.setDriverComparator(compFact, 1);
		reduceConfig.setRelativeMemoryDriver(memoryFraction);

		// udf
		reduceConfig.setStubWrapper(new UserCodeClassWrapper<>(MockReduceStub.class));

		getTaskConfig().addChainedTask(ChainedAllReduceDriver.class, reduceConfig, "reduce");
	}

	// chained map+reduce
	{
		registerTask(FlatMapDriver.class, MockMapStub.class);
		BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);

		testTask.invoke();
	}

	int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;

	Assert.assertEquals(1, this.outList.size());
	Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
}
 
Example 10
Source File: JobGraphGenerator.java    From flink with Apache License 2.0 4 votes vote down vote up
private void addLocalInfoFromChannelToConfig(Channel channel, TaskConfig config, int inputNum, boolean isBroadcastChannel) {
	// serializer
	if (isBroadcastChannel) {
		config.setBroadcastInputSerializer(channel.getSerializer(), inputNum);
		
		if (channel.getLocalStrategy() != LocalStrategy.NONE || (channel.getTempMode() != null && channel.getTempMode() != TempMode.NONE)) {
			throw new CompilerException("Found local strategy or temp mode on a broadcast variable channel.");
		} else {
			return;
		}
	} else {
		config.setInputSerializer(channel.getSerializer(), inputNum);
	}
	
	// local strategy
	if (channel.getLocalStrategy() != LocalStrategy.NONE) {
		config.setInputLocalStrategy(inputNum, channel.getLocalStrategy());
		if (channel.getLocalStrategyComparator() != null) {
			config.setInputComparator(channel.getLocalStrategyComparator(), inputNum);
		}
	}
	
	assignLocalStrategyResources(channel, config, inputNum);
	
	// materialization / caching
	if (channel.getTempMode() != null) {
		final TempMode tm = channel.getTempMode();

		boolean needsMemory = false;
		// Don't add a pipeline breaker if the data exchange is already blocking, EXCEPT the channel is within an iteration.
		if (tm.breaksPipeline() &&
				(channel.isOnDynamicPath() || channel.getDataExchangeMode() != DataExchangeMode.BATCH) ) {
			config.setInputAsynchronouslyMaterialized(inputNum, true);
			needsMemory = true;
		}
		if (tm.isCached()) {
			config.setInputCached(inputNum, true);
			needsMemory = true;
		}
		
		if (needsMemory) {
			// sanity check
			if (tm == TempMode.NONE || channel.getRelativeTempMemory() <= 0) {
				throw new CompilerException("Bug in compiler: Inconsistent description of input materialization.");
			}
			config.setRelativeInputMaterializationMemory(inputNum, channel.getRelativeTempMemory());
		}
	}
}
 
Example 11
Source File: ChainedAllReduceDriverTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMapTask() throws Exception {
	final int keyCnt = 100;
	final int valCnt = 20;

	final double memoryFraction = 1.0;

	// environment
	initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	mockEnv.getExecutionConfig().enableObjectReuse();
	addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
	addOutput(this.outList);

	// chained reduce config
	{
		final TaskConfig reduceConfig = new TaskConfig(new Configuration());

		// input
		reduceConfig.addInputToGroup(0);
		reduceConfig.setInputSerializer(serFact, 0);

		// output
		reduceConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
		reduceConfig.setOutputSerializer(serFact);

		// driver
		reduceConfig.setDriverStrategy(DriverStrategy.ALL_REDUCE);
		reduceConfig.setDriverComparator(compFact, 0);
		reduceConfig.setDriverComparator(compFact, 1);
		reduceConfig.setRelativeMemoryDriver(memoryFraction);

		// udf
		reduceConfig.setStubWrapper(new UserCodeClassWrapper<>(MockReduceStub.class));

		getTaskConfig().addChainedTask(ChainedAllReduceDriver.class, reduceConfig, "reduce");
	}

	// chained map+reduce
	{
		registerTask(FlatMapDriver.class, MockMapStub.class);
		BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);

		testTask.invoke();
	}

	int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;

	Assert.assertEquals(1, this.outList.size());
	Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
}
 
Example 12
Source File: JobGraphGenerator.java    From flink with Apache License 2.0 4 votes vote down vote up
private void addLocalInfoFromChannelToConfig(Channel channel, TaskConfig config, int inputNum, boolean isBroadcastChannel) {
	// serializer
	if (isBroadcastChannel) {
		config.setBroadcastInputSerializer(channel.getSerializer(), inputNum);
		
		if (channel.getLocalStrategy() != LocalStrategy.NONE || (channel.getTempMode() != null && channel.getTempMode() != TempMode.NONE)) {
			throw new CompilerException("Found local strategy or temp mode on a broadcast variable channel.");
		} else {
			return;
		}
	} else {
		config.setInputSerializer(channel.getSerializer(), inputNum);
	}
	
	// local strategy
	if (channel.getLocalStrategy() != LocalStrategy.NONE) {
		config.setInputLocalStrategy(inputNum, channel.getLocalStrategy());
		if (channel.getLocalStrategyComparator() != null) {
			config.setInputComparator(channel.getLocalStrategyComparator(), inputNum);
		}
	}
	
	assignLocalStrategyResources(channel, config, inputNum);
	
	// materialization / caching
	if (channel.getTempMode() != null) {
		final TempMode tm = channel.getTempMode();

		boolean needsMemory = false;
		// Don't add a pipeline breaker if the data exchange is already blocking, EXCEPT the channel is within an iteration.
		if (tm.breaksPipeline() &&
				(channel.isOnDynamicPath() || channel.getDataExchangeMode() != DataExchangeMode.BATCH) ) {
			config.setInputAsynchronouslyMaterialized(inputNum, true);
			needsMemory = true;
		}
		if (tm.isCached()) {
			config.setInputCached(inputNum, true);
			needsMemory = true;
		}
		
		if (needsMemory) {
			// sanity check
			if (tm == TempMode.NONE || channel.getRelativeTempMemory() <= 0) {
				throw new CompilerException("Bug in compiler: Inconsistent description of input materialization.");
			}
			config.setRelativeInputMaterializationMemory(inputNum, channel.getRelativeTempMemory());
		}
	}
}