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

The following examples show how to use org.apache.flink.core.memory.DataInputDeserializer#readBoolean() . 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: KvStateSerializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes all kv pairs with the given serializer.
 *
 * @param serializedValue Serialized value of type Map<UK, UV>
 * @param keySerializer   Serializer for UK
 * @param valueSerializer Serializer for UV
 * @param <UK>            Type of the key
 * @param <UV>            Type of the value.
 * @return Deserialized map or <code>null</code> if the serialized value
 * is <code>null</code>
 * @throws IOException On failure during deserialization
 */
public static <UK, UV> Map<UK, UV> deserializeMap(byte[] serializedValue, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException {
	if (serializedValue != null) {
		DataInputDeserializer in = new DataInputDeserializer(serializedValue, 0, serializedValue.length);

		Map<UK, UV> result = new HashMap<>();
		while (in.available() > 0) {
			UK key = keySerializer.deserialize(in);

			boolean isNull = in.readBoolean();
			UV value = isNull ? null : valueSerializer.deserialize(in);

			result.put(key, value);
		}

		return result;
	} else {
		return null;
	}
}
 
Example 2
Source File: RocksDBMapState.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void migrateSerializedValue(
	DataInputDeserializer serializedOldValueInput,
	DataOutputSerializer serializedMigratedValueOutput,
	TypeSerializer<Map<UK, UV>> priorSerializer,
	TypeSerializer<Map<UK, UV>> newSerializer) throws StateMigrationException {

	checkArgument(priorSerializer instanceof MapSerializer);
	checkArgument(newSerializer instanceof MapSerializer);

	TypeSerializer<UV> priorMapValueSerializer = ((MapSerializer<UK, UV>) priorSerializer).getValueSerializer();
	TypeSerializer<UV> newMapValueSerializer = ((MapSerializer<UK, UV>) newSerializer).getValueSerializer();

	try {
		boolean isNull = serializedOldValueInput.readBoolean();
		UV mapUserValue = null;
		if (!isNull) {
			mapUserValue = priorMapValueSerializer.deserialize(serializedOldValueInput);
		}
		serializedMigratedValueOutput.writeBoolean(mapUserValue == null);
		newMapValueSerializer.serialize(mapUserValue, serializedMigratedValueOutput);
	} catch (Exception e) {
		throw new StateMigrationException("Error while trying to migrate RocksDB map state.", e);
	}
}
 
Example 3
Source File: KvStateSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes all kv pairs with the given serializer.
 *
 * @param serializedValue Serialized value of type Map&lt;UK, UV&gt;
 * @param keySerializer   Serializer for UK
 * @param valueSerializer Serializer for UV
 * @param <UK>            Type of the key
 * @param <UV>            Type of the value.
 * @return Deserialized map or <code>null</code> if the serialized value
 * is <code>null</code>
 * @throws IOException On failure during deserialization
 */
public static <UK, UV> Map<UK, UV> deserializeMap(byte[] serializedValue, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException {
	if (serializedValue != null) {
		DataInputDeserializer in = new DataInputDeserializer(serializedValue, 0, serializedValue.length);

		Map<UK, UV> result = new HashMap<>();
		while (in.available() > 0) {
			UK key = keySerializer.deserialize(in);

			boolean isNull = in.readBoolean();
			UV value = isNull ? null : valueSerializer.deserialize(in);

			result.put(key, value);
		}

		return result;
	} else {
		return null;
	}
}
 
Example 4
Source File: RocksDBMapState.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void migrateSerializedValue(
	DataInputDeserializer serializedOldValueInput,
	DataOutputSerializer serializedMigratedValueOutput,
	TypeSerializer<Map<UK, UV>> priorSerializer,
	TypeSerializer<Map<UK, UV>> newSerializer) throws StateMigrationException {

	checkArgument(priorSerializer instanceof MapSerializer);
	checkArgument(newSerializer instanceof MapSerializer);

	TypeSerializer<UV> priorMapValueSerializer = ((MapSerializer<UK, UV>) priorSerializer).getValueSerializer();
	TypeSerializer<UV> newMapValueSerializer = ((MapSerializer<UK, UV>) newSerializer).getValueSerializer();

	try {
		boolean isNull = serializedOldValueInput.readBoolean();
		UV mapUserValue = null;
		if (!isNull) {
			mapUserValue = priorMapValueSerializer.deserialize(serializedOldValueInput);
		}
		serializedMigratedValueOutput.writeBoolean(mapUserValue == null);
		newMapValueSerializer.serialize(mapUserValue, serializedMigratedValueOutput);
	} catch (Exception e) {
		throw new StateMigrationException("Error while trying to migrate RocksDB map state.", e);
	}
}
 
Example 5
Source File: KvStateSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes all kv pairs with the given serializer.
 *
 * @param serializedValue Serialized value of type Map&lt;UK, UV&gt;
 * @param keySerializer   Serializer for UK
 * @param valueSerializer Serializer for UV
 * @param <UK>            Type of the key
 * @param <UV>            Type of the value.
 * @return Deserialized map or <code>null</code> if the serialized value
 * is <code>null</code>
 * @throws IOException On failure during deserialization
 */
public static <UK, UV> Map<UK, UV> deserializeMap(byte[] serializedValue, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException {
	if (serializedValue != null) {
		DataInputDeserializer in = new DataInputDeserializer(serializedValue, 0, serializedValue.length);

		Map<UK, UV> result = new HashMap<>();
		while (in.available() > 0) {
			UK key = keySerializer.deserialize(in);

			boolean isNull = in.readBoolean();
			UV value = isNull ? null : valueSerializer.deserialize(in);

			result.put(key, value);
		}

		return result;
	} else {
		return null;
	}
}
 
Example 6
Source File: RocksDBMapState.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static <UV> UV deserializeUserValue(
	DataInputDeserializer dataInputView,
	byte[] rawValueBytes,
	TypeSerializer<UV> valueSerializer) throws IOException {

	dataInputView.setBuffer(rawValueBytes);

	boolean isNull = dataInputView.readBoolean();

	return isNull ? null : valueSerializer.deserialize(dataInputView);
}
 
Example 7
Source File: RocksDBMapState.java    From flink with Apache License 2.0 5 votes vote down vote up
private static <UV> UV deserializeUserValue(
	DataInputDeserializer dataInputView,
	byte[] rawValueBytes,
	TypeSerializer<UV> valueSerializer) throws IOException {

	dataInputView.setBuffer(rawValueBytes);

	boolean isNull = dataInputView.readBoolean();

	return isNull ? null : valueSerializer.deserialize(dataInputView);
}
 
Example 8
Source File: RocksDBMapState.java    From flink with Apache License 2.0 5 votes vote down vote up
private static <UV> UV deserializeUserValue(
	DataInputDeserializer dataInputView,
	byte[] rawValueBytes,
	TypeSerializer<UV> valueSerializer) throws IOException {

	dataInputView.setBuffer(rawValueBytes);

	boolean isNull = dataInputView.readBoolean();

	return isNull ? null : valueSerializer.deserialize(dataInputView);
}