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

The following examples show how to use org.apache.flink.runtime.operators.util.TaskConfig#setOutputSerializer() . 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: JobGraphGenerator.java    From flink with Apache License 2.0 6 votes vote down vote up
private JobVertex createDataSourceVertex(SourcePlanNode node) throws CompilerException {
	final InputOutputFormatVertex vertex = new InputOutputFormatVertex(node.getNodeName());
	final TaskConfig config = new TaskConfig(vertex.getConfiguration());

	final OperatorID operatorID = new OperatorID();

	vertex.setResources(node.getMinResources(), node.getPreferredResources());
	vertex.setInvokableClass(DataSourceTask.class);
	vertex.setFormatDescription(operatorID, getDescriptionForUserCode(node.getProgramOperator().getUserCodeWrapper()));

	// set user code
	new InputOutputFormatContainer(Thread.currentThread().getContextClassLoader())
		.addInputFormat(operatorID, (UserCodeWrapper<? extends InputFormat<?, ?>>) node.getProgramOperator().getUserCodeWrapper())
		.addParameters(operatorID, node.getProgramOperator().getParameters())
		.write(config);

	config.setOutputSerializer(node.getSerializer());
	return vertex;
}
 
Example 4
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 5
Source File: JobGraphGenerator.java    From flink with Apache License 2.0 6 votes vote down vote up
private JobVertex createDataSourceVertex(SourcePlanNode node) throws CompilerException {
	final InputOutputFormatVertex vertex = new InputOutputFormatVertex(node.getNodeName());
	final TaskConfig config = new TaskConfig(vertex.getConfiguration());

	final OperatorID operatorID = new OperatorID();

	vertex.setResources(node.getMinResources(), node.getPreferredResources());
	vertex.setInvokableClass(DataSourceTask.class);
	vertex.setFormatDescription(operatorID, getDescriptionForUserCode(node.getProgramOperator().getUserCodeWrapper()));

	// set user code
	new InputOutputFormatContainer(Thread.currentThread().getContextClassLoader())
		.addInputFormat(operatorID, (UserCodeWrapper<? extends InputFormat<?, ?>>) node.getProgramOperator().getUserCodeWrapper())
		.addParameters(operatorID, node.getProgramOperator().getParameters())
		.write(config);

	config.setOutputSerializer(node.getSerializer());
	return vertex;
}
 
Example 6
Source File: JobGraphGenerator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private InputFormatVertex createDataSourceVertex(SourcePlanNode node) throws CompilerException {
	final InputFormatVertex vertex = new InputFormatVertex(node.getNodeName());
	final TaskConfig config = new TaskConfig(vertex.getConfiguration());

	vertex.setResources(node.getMinResources(), node.getPreferredResources());
	vertex.setInvokableClass(DataSourceTask.class);
	vertex.setFormatDescription(getDescriptionForUserCode(node.getProgramOperator().getUserCodeWrapper()));

	// set user code
	config.setStubWrapper(node.getProgramOperator().getUserCodeWrapper());
	config.setStubParameters(node.getProgramOperator().getParameters());

	config.setOutputSerializer(node.getSerializer());
	return vertex;
}
 
Example 7
Source File: ChainTaskTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchTaskOutputInCloseMethod() {
	final int numChainedTasks = 10;
	final int keyCnt = 100;
	final int valCnt = 10;
	try {
		initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
		addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
		addOutput(outList);
		registerTask(FlatMapDriver.class, MockMapStub.class);
		for (int i = 0; i < numChainedTasks; i++) {
			final TaskConfig taskConfig = new TaskConfig(new Configuration());
			taskConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
			taskConfig.setOutputSerializer(serFact);
			taskConfig.setStubWrapper(
				new UserCodeClassWrapper<>(MockDuplicateLastValueMapFunction.class));
			getTaskConfig().addChainedTask(
				ChainedFlatMapDriver.class, taskConfig, "chained-" + i);
		}
		final BatchTask<FlatMapFunction<Record, Record>, Record> testTask =
			new BatchTask<>(mockEnv);
		testTask.invoke();
		Assert.assertEquals(keyCnt * valCnt + numChainedTasks, outList.size());
	}
	catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example 8
Source File: ChainTaskTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDataSourceTaskOutputInCloseMethod() throws IOException {
	final int numChainedTasks = 10;
	final int keyCnt = 100;
	final int valCnt = 10;
	final File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
	DataSourceTaskTest.InputFilePreparator.prepareInputFile(
		new UniformRecordGenerator(keyCnt, valCnt, false), tempTestFile, true);
	initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	addOutput(outList);
	final DataSourceTask<Record> testTask = new DataSourceTask<>(mockEnv);
	registerFileInputTask(
		testTask, DataSourceTaskTest.MockInputFormat.class, tempTestFile.toURI().toString(), "\n");
	for (int i = 0; i < numChainedTasks; i++) {
		final TaskConfig taskConfig = new TaskConfig(new Configuration());
		taskConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
		taskConfig.setOutputSerializer(serFact);
		taskConfig.setStubWrapper(
			new UserCodeClassWrapper<>(ChainTaskTest.MockDuplicateLastValueMapFunction.class));
		getTaskConfig().addChainedTask(
			ChainedFlatMapDriver.class, taskConfig, "chained-" + i);
	}
	try {
		testTask.invoke();
		Assert.assertEquals(keyCnt * valCnt + numChainedTasks, outList.size());
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail("Invoke method caused exception.");
	}
}
 
Example 9
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 10
Source File: TaskTestBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void addOutput(List<Record> output) {
	this.mockEnv.addOutput(output);
	TaskConfig conf = new TaskConfig(this.mockEnv.getTaskConfiguration());
	conf.addOutputShipStrategy(ShipStrategyType.FORWARD);
	conf.setOutputSerializer(RecordSerializerFactory.get());
}
 
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: TaskTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
public void addOutput(List<Record> output) {
	this.mockEnv.addOutput(output);
	TaskConfig conf = new TaskConfig(this.mockEnv.getTaskConfiguration());
	conf.addOutputShipStrategy(ShipStrategyType.FORWARD);
	conf.setOutputSerializer(RecordSerializerFactory.get());
}
 
Example 13
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 14
Source File: TaskTestBase.java    From flink with Apache License 2.0 4 votes vote down vote up
public void addOutput(List<Record> output) {
	this.mockEnv.addOutput(output);
	TaskConfig conf = new TaskConfig(this.mockEnv.getTaskConfiguration());
	conf.addOutputShipStrategy(ShipStrategyType.FORWARD);
	conf.setOutputSerializer(RecordSerializerFactory.get());
}