Java Code Examples for org.apache.flink.core.memory.DataOutputSerializer#writeBoolean()
The following examples show how to use
org.apache.flink.core.memory.DataOutputSerializer#writeBoolean() .
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 |
/** * Serializes all values of the Iterable with the given serializer. * * @param entries Key-value pairs to serialize * @param keySerializer Serializer for UK * @param valueSerializer Serializer for UV * @param <UK> Type of the keys * @param <UV> Type of the values * @return Serialized values or <code>null</code> if values <code>null</code> or empty * @throws IOException On failure during serialization */ public static <UK, UV> byte[] serializeMap(Iterable<Map.Entry<UK, UV>> entries, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException { if (entries != null) { // Serialize DataOutputSerializer dos = new DataOutputSerializer(32); for (Map.Entry<UK, UV> entry : entries) { keySerializer.serialize(entry.getKey(), dos); if (entry.getValue() == null) { dos.writeBoolean(true); } else { dos.writeBoolean(false); valueSerializer.serialize(entry.getValue(), dos); } } return dos.getCopyOfBuffer(); } else { return null; } }
Example 2
Source File: RocksDBMapState.java From flink with Apache License 2.0 | 6 votes |
@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 |
/** * Serializes all values of the Iterable with the given serializer. * * @param entries Key-value pairs to serialize * @param keySerializer Serializer for UK * @param valueSerializer Serializer for UV * @param <UK> Type of the keys * @param <UV> Type of the values * @return Serialized values or <code>null</code> if values <code>null</code> or empty * @throws IOException On failure during serialization */ public static <UK, UV> byte[] serializeMap(Iterable<Map.Entry<UK, UV>> entries, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException { if (entries != null) { // Serialize DataOutputSerializer dos = new DataOutputSerializer(32); for (Map.Entry<UK, UV> entry : entries) { keySerializer.serialize(entry.getKey(), dos); if (entry.getValue() == null) { dos.writeBoolean(true); } else { dos.writeBoolean(false); valueSerializer.serialize(entry.getValue(), dos); } } return dos.getCopyOfBuffer(); } else { return null; } }
Example 4
Source File: RocksDBMapState.java From flink with Apache License 2.0 | 6 votes |
@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 |
/** * Serializes all values of the Iterable with the given serializer. * * @param entries Key-value pairs to serialize * @param keySerializer Serializer for UK * @param valueSerializer Serializer for UV * @param <UK> Type of the keys * @param <UV> Type of the values * @return Serialized values or <code>null</code> if values <code>null</code> or empty * @throws IOException On failure during serialization */ public static <UK, UV> byte[] serializeMap(Iterable<Map.Entry<UK, UV>> entries, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException { if (entries != null) { // Serialize DataOutputSerializer dos = new DataOutputSerializer(32); for (Map.Entry<UK, UV> entry : entries) { keySerializer.serialize(entry.getKey(), dos); if (entry.getValue() == null) { dos.writeBoolean(true); } else { dos.writeBoolean(false); valueSerializer.serialize(entry.getValue(), dos); } } return dos.getCopyOfBuffer(); } else { return null; } }