Java Code Examples for org.apache.flink.api.common.typeutils.TypeSerializer#copy()

The following examples show how to use org.apache.flink.api.common.typeutils.TypeSerializer#copy() . 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: FlatMapOperatorBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> input, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	FlatMapFunction<IN, OUT> function = userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, parameters);

	ArrayList<OUT> result = new ArrayList<OUT>(input.size());

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

	CopyingListCollector<OUT> resultCollector = new CopyingListCollector<OUT>(result, outSerializer);

	for (IN element : input) {
		IN inCopy = inSerializer.copy(element);
		function.flatMap(inCopy, resultCollector);
	}

	FunctionUtils.closeFunction(function);

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

	ArrayList<OUT> result = new ArrayList<OUT>(input.size());

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

	CopyingListCollector<OUT> resultCollector = new CopyingListCollector<OUT>(result, outSerializer);

	for (IN element : input) {
		IN inCopy = inSerializer.copy(element);
		function.flatMap(inCopy, resultCollector);
	}

	FunctionUtils.closeFunction(function);

	return result;
}
 
Example 3
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 4
Source File: FlatMapOperatorBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected List<OUT> executeOnCollections(List<IN> input, RuntimeContext ctx, ExecutionConfig executionConfig) throws Exception {
	FlatMapFunction<IN, OUT> function = userFunction.getUserCodeObject();
	
	FunctionUtils.setFunctionRuntimeContext(function, ctx);
	FunctionUtils.openFunction(function, parameters);

	ArrayList<OUT> result = new ArrayList<OUT>(input.size());

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

	CopyingListCollector<OUT> resultCollector = new CopyingListCollector<OUT>(result, outSerializer);

	for (IN element : input) {
		IN inCopy = inSerializer.copy(element);
		function.flatMap(inCopy, resultCollector);
	}

	FunctionUtils.closeFunction(function);

	return result;
}
 
Example 5
Source File: UnionSerializer.java    From da-streamingledger with Apache License 2.0 5 votes vote down vote up
@Override
public TaggedElement copy(TaggedElement from, TaggedElement reuse) {
    final int tag = from.getDataStreamTag();
    final TypeSerializer<Object> serializer = underlyingSerializers[tag];
    final Object elementCopy = serializer.copy(from.getElement(), reusableObjects[tag]);

    reuse.setElement(elementCopy);
    reuse.setDataStreamTag(tag);
    return reuse;
}
 
Example 6
Source File: TaggedBootstrapDataSerializer.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
@Override
public TaggedBootstrapData copy(TaggedBootstrapData bootstrapData, TaggedBootstrapData reuse) {
  final int unionIndex = bootstrapData.getUnionIndex();
  final TypeSerializer<Object> payloadSerializer = payloadSerializers[unionIndex];
  final Object reusedPayloadCopy =
      payloadSerializer.copy(bootstrapData.getPayload(), reusablePayloadObjects[unionIndex]);

  final Address address = bootstrapData.getTarget();
  reuse.setTarget(new Address(address.type(), address.id()));
  reuse.setPayload(reusedPayloadCopy);
  reuse.setUnionIndex(bootstrapData.getUnionIndex());

  return reuse;
}
 
Example 7
Source File: StateDescriptor.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default value.
 */
public T getDefaultValue() {
	if (defaultValue != null) {
		TypeSerializer<T> serializer = serializerAtomicReference.get();
		if (serializer != null) {
			return serializer.copy(defaultValue);
		} else {
			throw new IllegalStateException("Serializer not yet initialized.");
		}
	} else {
		return null;
	}
}
 
Example 8
Source File: StateDescriptor.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default value.
 */
public T getDefaultValue() {
	if (defaultValue != null) {
		TypeSerializer<T> serializer = serializerAtomicReference.get();
		if (serializer != null) {
			return serializer.copy(defaultValue);
		} else {
			throw new IllegalStateException("Serializer not yet initialized.");
		}
	} else {
		return null;
	}
}
 
Example 9
Source File: TaggedBootstrapData.java    From stateful-functions with Apache License 2.0 4 votes vote down vote up
public TaggedBootstrapData copy(TypeSerializer<Object> payloadSerializer) {
  return new TaggedBootstrapData(
      new Address(target.type(), target.id()), payloadSerializer.copy(payload), unionIndex);
}
 
Example 10
Source File: PojoSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	// copy the flags
	int flags = source.readByte();
	target.writeByte(flags);

	if ((flags & IS_NULL) != 0) {
		// is a null value, nothing further to copy
		return;
	}

	TypeSerializer<?> subclassSerializer = null;
	if ((flags & IS_SUBCLASS) != 0) {
		String className = source.readUTF();
		target.writeUTF(className);
		try {
			Class<?> subclass = Class.forName(className, true, Thread.currentThread()
					.getContextClassLoader());
			subclassSerializer = getSubclassSerializer(subclass);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException("Cannot instantiate class.", e);
		}
	} else if ((flags & IS_TAGGED_SUBCLASS) != 0) {
		int subclassTag = source.readByte();
		target.writeByte(subclassTag);
		subclassSerializer = registeredSerializers[subclassTag];
	}

	if ((flags & NO_SUBCLASS) != 0) {
		for (int i = 0; i < numFields; i++) {
			boolean isNull = source.readBoolean();
			target.writeBoolean(isNull);
			if (!isNull) {
				fieldSerializers[i].copy(source, target);
			}
		}
	} else {
		if (subclassSerializer != null) {
			subclassSerializer.copy(source, target);
		}
	}
}
 
Example 11
Source File: TaggedBootstrapData.java    From flink-statefun with Apache License 2.0 4 votes vote down vote up
public TaggedBootstrapData copy(TypeSerializer<Object> payloadSerializer) {
  return new TaggedBootstrapData(
      new Address(target.type(), target.id()), payloadSerializer.copy(payload), unionIndex);
}
 
Example 12
Source File: NonReusingMergeInnerJoinIterator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T createCopy(TypeSerializer<T> serializer, T value, T reuse) {
	return serializer.copy(value);
}
 
Example 13
Source File: NonReusingMergeOuterJoinIterator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T createCopy(TypeSerializer<T> serializer, T value, T reuse) {
	return serializer.copy(value);
}
 
Example 14
Source File: ReusingMergeInnerJoinIterator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T createCopy(TypeSerializer<T> serializer, T value, T reuse) {
	return serializer.copy(value, reuse);
}
 
Example 15
Source File: ReusingMergeOuterJoinIterator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T createCopy(TypeSerializer<T> serializer, T value, T reuse) { return serializer.copy(value, reuse); }
 
Example 16
Source File: ReusingMergeOuterJoinIterator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T createCopy(TypeSerializer<T> serializer, T value, T reuse) { return serializer.copy(value, reuse); }
 
Example 17
Source File: PojoSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	// copy the flags
	int flags = source.readByte();
	target.writeByte(flags);

	if ((flags & IS_NULL) != 0) {
		// is a null value, nothing further to copy
		return;
	}

	TypeSerializer<?> subclassSerializer = null;
	if ((flags & IS_SUBCLASS) != 0) {
		String className = source.readUTF();
		target.writeUTF(className);
		try {
			Class<?> subclass = Class.forName(className, true, Thread.currentThread()
					.getContextClassLoader());
			subclassSerializer = getSubclassSerializer(subclass);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException("Cannot instantiate class.", e);
		}
	} else if ((flags & IS_TAGGED_SUBCLASS) != 0) {
		int subclassTag = source.readByte();
		target.writeByte(subclassTag);
		subclassSerializer = registeredSerializers[subclassTag];
	}

	if ((flags & NO_SUBCLASS) != 0) {
		for (int i = 0; i < numFields; i++) {
			boolean isNull = source.readBoolean();
			target.writeBoolean(isNull);
			if (!isNull) {
				fieldSerializers[i].copy(source, target);
			}
		}
	} else {
		if (subclassSerializer != null) {
			subclassSerializer.copy(source, target);
		}
	}
}
 
Example 18
Source File: ReusingMergeOuterJoinIterator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T createCopy(TypeSerializer<T> serializer, T value, T reuse) { return serializer.copy(value, reuse); }
 
Example 19
Source File: NonReusingMergeInnerJoinIterator.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T createCopy(TypeSerializer<T> serializer, T value, T reuse) {
	return serializer.copy(value);
}
 
Example 20
Source File: PojoSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
	// copy the flags
	int flags = source.readByte();
	target.writeByte(flags);

	if ((flags & IS_NULL) != 0) {
		// is a null value, nothing further to copy
		return;
	}

	TypeSerializer<?> subclassSerializer = null;
	if ((flags & IS_SUBCLASS) != 0) {
		String className = source.readUTF();
		target.writeUTF(className);
		try {
			Class<?> subclass = Class.forName(className, true, Thread.currentThread()
					.getContextClassLoader());
			subclassSerializer = getSubclassSerializer(subclass);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException("Cannot instantiate class.", e);
		}
	} else if ((flags & IS_TAGGED_SUBCLASS) != 0) {
		int subclassTag = source.readByte();
		target.writeByte(subclassTag);
		subclassSerializer = registeredSerializers[subclassTag];
	}

	if ((flags & NO_SUBCLASS) != 0) {
		for (int i = 0; i < numFields; i++) {
			boolean isNull = source.readBoolean();
			target.writeBoolean(isNull);
			if (!isNull) {
				fieldSerializers[i].copy(source, target);
			}
		}
	} else {
		if (subclassSerializer != null) {
			subclassSerializer.copy(source, target);
		}
	}
}