Java Code Examples for org.apache.flink.core.memory.DataInputDeserializer#getPosition()

The following examples show how to use org.apache.flink.core.memory.DataInputDeserializer#getPosition() . 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: RocksDBListState.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public byte[] filterOrTransform(@Nullable byte[] value) {
	if (value == null) {
		return null;
	}
	List<T> result = new ArrayList<>();
	DataInputDeserializer in = new DataInputDeserializer(value);
	T next;
	int prevPosition = 0;
	while ((next = deserializeNextElement(in, elementSerializer)) != null) {
		T transformedElement = elementTransformer.filterOrTransform(next);
		if (transformedElement != null) {
			if (transformStrategy == STOP_ON_FIRST_INCLUDED) {
				return Arrays.copyOfRange(value, prevPosition, value.length);
			} else {
				result.add(transformedElement);
			}
		}
		prevPosition = in.getPosition();
	}
	try {
		return result.isEmpty() ? null : serializeValueList(result, elementSerializer, DELIMITER);
	} catch (IOException e) {
		throw new FlinkRuntimeException("Failed to serialize transformed list", e);
	}
}
 
Example 2
Source File: RocksDBKeySerializationUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static <K> K readKey(
	TypeSerializer<K> keySerializer,
	DataInputDeserializer inputView,
	boolean ambiguousKeyPossible) throws IOException {
	int beforeRead = inputView.getPosition();
	K key = keySerializer.deserialize(inputView);
	if (ambiguousKeyPossible) {
		int length = inputView.getPosition() - beforeRead;
		readVariableIntBytes(inputView, length);
	}
	return key;
}
 
Example 3
Source File: RocksDBKeySerializationUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static <N> N readNamespace(
	TypeSerializer<N> namespaceSerializer,
	DataInputDeserializer inputView,
	boolean ambiguousKeyPossible) throws IOException {
	int beforeRead = inputView.getPosition();
	N namespace = namespaceSerializer.deserialize(inputView);
	if (ambiguousKeyPossible) {
		int length = inputView.getPosition() - beforeRead;
		readVariableIntBytes(inputView, length);
	}
	return namespace;
}
 
Example 4
Source File: RocksDBListState.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public byte[] filterOrTransform(@Nullable byte[] value) {
	if (value == null) {
		return null;
	}
	List<T> result = new ArrayList<>();
	DataInputDeserializer in = new DataInputDeserializer(value);
	T next;
	int prevPosition = 0;
	while ((next = deserializeNextElement(in, elementSerializer)) != null) {
		T transformedElement = elementTransformer.filterOrTransform(next);
		if (transformedElement != null) {
			if (transformStrategy == STOP_ON_FIRST_INCLUDED) {
				return Arrays.copyOfRange(value, prevPosition, value.length);
			} else {
				result.add(transformedElement);
			}
		}
		prevPosition = in.getPosition();
	}
	try {
		return result.isEmpty() ? null : serializeValueList(result, elementSerializer, DELIMITER);
	} catch (IOException e) {
		throw new FlinkRuntimeException("Failed to serialize transformed list", e);
	}
}
 
Example 5
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <K> K readKey(
	TypeSerializer<K> keySerializer,
	DataInputDeserializer inputView,
	boolean ambiguousKeyPossible) throws IOException {
	int beforeRead = inputView.getPosition();
	K key = keySerializer.deserialize(inputView);
	if (ambiguousKeyPossible) {
		int length = inputView.getPosition() - beforeRead;
		readVariableIntBytes(inputView, length);
	}
	return key;
}
 
Example 6
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <N> N readNamespace(
	TypeSerializer<N> namespaceSerializer,
	DataInputDeserializer inputView,
	boolean ambiguousKeyPossible) throws IOException {
	int beforeRead = inputView.getPosition();
	N namespace = namespaceSerializer.deserialize(inputView);
	if (ambiguousKeyPossible) {
		int length = inputView.getPosition() - beforeRead;
		readVariableIntBytes(inputView, length);
	}
	return namespace;
}
 
Example 7
Source File: RocksDBListState.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public byte[] filterOrTransform(@Nullable byte[] value) {
	if (value == null) {
		return null;
	}
	List<T> result = new ArrayList<>();
	DataInputDeserializer in = new DataInputDeserializer(value);
	T next;
	int prevPosition = 0;
	while ((next = deserializeNextElement(in, elementSerializer)) != null) {
		T transformedElement = elementTransformer.filterOrTransform(next);
		if (transformedElement != null) {
			if (transformStrategy == STOP_ON_FIRST_INCLUDED) {
				return Arrays.copyOfRange(value, prevPosition, value.length);
			} else {
				result.add(transformedElement);
			}
		}
		prevPosition = in.getPosition();
	}
	try {
		return result.isEmpty() ? null : serializeValueList(result, elementSerializer, DELIMITER);
	} catch (IOException e) {
		throw new FlinkRuntimeException("Failed to serialize transformed list", e);
	}
}
 
Example 8
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <K> K readKey(
	TypeSerializer<K> keySerializer,
	DataInputDeserializer inputView,
	boolean ambiguousKeyPossible) throws IOException {
	int beforeRead = inputView.getPosition();
	K key = keySerializer.deserialize(inputView);
	if (ambiguousKeyPossible) {
		int length = inputView.getPosition() - beforeRead;
		readVariableIntBytes(inputView, length);
	}
	return key;
}
 
Example 9
Source File: RocksDBKeySerializationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <N> N readNamespace(
	TypeSerializer<N> namespaceSerializer,
	DataInputDeserializer inputView,
	boolean ambiguousKeyPossible) throws IOException {
	int beforeRead = inputView.getPosition();
	N namespace = namespaceSerializer.deserialize(inputView);
	if (ambiguousKeyPossible) {
		int length = inputView.getPosition() - beforeRead;
		readVariableIntBytes(inputView, length);
	}
	return namespace;
}