Java Code Examples for org.apache.flink.api.common.functions.MapFunction#map()

The following examples show how to use org.apache.flink.api.common.functions.MapFunction#map() . 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: MapOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	MapFunction<IN, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<OUT> result = new ArrayList<OUT>(inputData.size());

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN element : inputData) {
		IN inCopy = inSerializer.copy(element);
		OUT out = function.map(inCopy);
		result.add(outSerializer.copy(out));
	}

	FunctionUtils.closeFunction(function);
	
	return result;
}
 
Example 2
Source File: MapOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	MapFunction<IN, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<OUT> result = new ArrayList<OUT>(inputData.size());

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN element : inputData) {
		IN inCopy = inSerializer.copy(element);
		OUT out = function.map(inCopy);
		result.add(outSerializer.copy(out));
	}

	FunctionUtils.closeFunction(function);
	
	return result;
}
 
Example 3
Source File: MapOperatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> inputData, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	MapFunction<IN, OUT> function = this.userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, this.parameters);
	
	ArrayList<OUT> result = new ArrayList<OUT>(inputData.size());

	TypeSerializer<IN> inSerializer = getOperatorInfo().getInputType().createSerializer(executionConfig);
	TypeSerializer<OUT> outSerializer = getOperatorInfo().getOutputType().createSerializer(executionConfig);

	for (IN element : inputData) {
		IN inCopy = inSerializer.copy(element);
		OUT out = function.map(inCopy);
		result.add(outSerializer.copy(out));
	}

	FunctionUtils.closeFunction(function);
	
	return result;
}
 
Example 4
Source File: ClosureCleanerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testCleanedNonSerializable() throws Exception  {
	MapCreator creator = new NonSerializableMapCreator();
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 5
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCleanedNonSerializable() throws Exception  {
	MapCreator creator = new NonSerializableMapCreator();
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 6
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testNestedNonSerializable() throws Exception  {
	MapCreator creator = new NestedNonSerializableMapCreator(1);
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 7
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testNestedNonSerializable() throws Exception  {
	MapCreator creator = new NestedNonSerializableMapCreator(1);
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 8
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNestedSerializable() throws Exception  {
	MapCreator creator = new NestedSerializableMapCreator(1);
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 9
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializable() throws Exception  {
	MapCreator creator = new SerializableMapCreator(1);
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 10
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCleanedNonSerializable() throws Exception  {
	MapCreator creator = new NonSerializableMapCreator();
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 11
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testNonSerializable() throws Exception  {
	MapCreator creator = new NonSerializableMapCreator();
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 12
Source File: ClosureCleanerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testNestedNonSerializable() throws Exception  {
	MapCreator creator = new NestedNonSerializableMapCreator(1);
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 13
Source File: ClosureCleanerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNestedSerializable() throws Exception  {
	MapCreator creator = new NestedSerializableMapCreator(1);
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 14
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNestedSerializable() throws Exception  {
	MapCreator creator = new NestedSerializableMapCreator(1);
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.clean(map, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 15
Source File: ClosureCleanerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidProgramException.class)
public void testNonSerializable() throws Exception  {
	MapCreator creator = new NonSerializableMapCreator();
	MapFunction<Integer, Integer> map = creator.getMap();

	ClosureCleaner.ensureSerializable(map);

	int result = map.map(3);
	Assert.assertEquals(result, 4);
}
 
Example 16
Source File: ClosureCleanerTest.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
@Test
public void testComplexInnerClassClean() throws Exception {
	MapFunction<Integer, Integer> complexMap = new InnerComplexMap((MapFunction<Integer, Integer>) value -> value + 1);

	ClosureCleaner.clean(complexMap, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = complexMap.map(3);

	Assert.assertEquals(result, 4);
}
 
Example 17
Source File: ClosureCleanerTest.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
@Test
public void testComplexTopLevelClassClean() throws Exception {
	MapFunction<Integer, Integer> complexMap = new ComplexMap((MapFunction<Integer, Integer>) value -> value + 1);

	ClosureCleaner.clean(complexMap, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = complexMap.map(3);

	Assert.assertEquals(result, 5);
}
 
Example 18
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 3 votes vote down vote up
@Test
public void testComplexTopLevelClassClean() throws Exception {
	MapFunction<Integer, Integer> complexMap = new ComplexMap((MapFunction<Integer, Integer>) value -> value + 1);

	ClosureCleaner.clean(complexMap, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = complexMap.map(3);

	Assert.assertEquals(result, 5);
}
 
Example 19
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 3 votes vote down vote up
@Test
public void testComplexInnerClassClean() throws Exception {
	MapFunction<Integer, Integer> complexMap = new InnerComplexMap((MapFunction<Integer, Integer>) value -> value + 1);

	ClosureCleaner.clean(complexMap, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = complexMap.map(3);

	Assert.assertEquals(result, 4);
}
 
Example 20
Source File: ClosureCleanerTest.java    From flink with Apache License 2.0 3 votes vote down vote up
@Test
public void testComplexInnerClassClean() throws Exception {
	MapFunction<Integer, Integer> complexMap = new InnerComplexMap((MapFunction<Integer, Integer>) value -> value + 1);

	ClosureCleaner.clean(complexMap, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);

	int result = complexMap.map(3);

	Assert.assertEquals(result, 4);
}