java.lang.Object
org.apache.flink.queryablestate.client.state.serialization.KvStateSerializer

public final class KvStateSerializer extends Object
Serialization and deserialization the different state types and namespaces.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <K, N> org.apache.flink.api.java.tuple.Tuple2<K,N>
    deserializeKeyAndNamespace(byte[] serializedKeyAndNamespace, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer)
    Deserializes the key and namespace into a Tuple2.
    static <T> List<T>
    deserializeList(byte[] serializedValue, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer)
    Deserializes all values with the given serializer.
    static <UK, UV> Map<UK,UV>
    deserializeMap(byte[] serializedValue, org.apache.flink.api.common.typeutils.TypeSerializer<UK> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<UV> valueSerializer)
    Deserializes all kv pairs with the given serializer.
    static <T> T
    deserializeValue(byte[] serializedValue, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer)
    Deserializes the value with the given serializer.
    static <K, N> byte[]
    serializeKeyAndNamespace(K key, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer)
    Serializes the key and namespace into a ByteBuffer.
    static <UK, UV> byte[]
    serializeMap(Iterable<Map.Entry<UK,UV>> entries, org.apache.flink.api.common.typeutils.TypeSerializer<UK> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<UV> valueSerializer)
    Serializes all values of the Iterable with the given serializer.
    static <T> byte[]
    serializeValue(T value, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer)
    Serializes the value with the given serializer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KvStateSerializer

      public KvStateSerializer()
  • Method Details

    • serializeKeyAndNamespace

      public static <K, N> byte[] serializeKeyAndNamespace(K key, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer) throws IOException
      Serializes the key and namespace into a ByteBuffer.

      The serialized format matches the RocksDB state backend key format, i.e. the key and namespace don't have to be deserialized for RocksDB lookups.

      Type Parameters:
      K - Key type
      N - Namespace type
      Parameters:
      key - Key to serialize
      keySerializer - Serializer for the key
      namespace - Namespace to serialize
      namespaceSerializer - Serializer for the namespace
      Returns:
      Buffer holding the serialized key and namespace
      Throws:
      IOException - Serialization errors are forwarded
    • deserializeKeyAndNamespace

      public static <K, N> org.apache.flink.api.java.tuple.Tuple2<K,N> deserializeKeyAndNamespace(byte[] serializedKeyAndNamespace, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer) throws IOException
      Deserializes the key and namespace into a Tuple2.
      Type Parameters:
      K - Key type
      N - Namespace
      Parameters:
      serializedKeyAndNamespace - Serialized key and namespace
      keySerializer - Serializer for the key
      namespaceSerializer - Serializer for the namespace
      Returns:
      Tuple2 holding deserialized key and namespace
      Throws:
      IOException - if the deserialization fails for any reason
    • serializeValue

      public static <T> byte[] serializeValue(T value, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) throws IOException
      Serializes the value with the given serializer.
      Type Parameters:
      T - Type of the value
      Parameters:
      value - Value of type T to serialize
      serializer - Serializer for T
      Returns:
      Serialized value or null if value null
      Throws:
      IOException - On failure during serialization
    • deserializeValue

      public static <T> T deserializeValue(byte[] serializedValue, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) throws IOException
      Deserializes the value with the given serializer.
      Type Parameters:
      T - Type of the value
      Parameters:
      serializedValue - Serialized value of type T
      serializer - Serializer for T
      Returns:
      Deserialized value or null if the serialized value is null
      Throws:
      IOException - On failure during deserialization
    • deserializeList

      public static <T> List<T> deserializeList(byte[] serializedValue, org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) throws IOException
      Deserializes all values with the given serializer.
      Type Parameters:
      T - Type of the value
      Parameters:
      serializedValue - Serialized value of type List<T>
      serializer - Serializer for T
      Returns:
      Deserialized list or null if the serialized value is null
      Throws:
      IOException - On failure during deserialization
    • serializeMap

      public static <UK, UV> byte[] serializeMap(Iterable<Map.Entry<UK,UV>> entries, org.apache.flink.api.common.typeutils.TypeSerializer<UK> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<UV> valueSerializer) throws IOException
      Serializes all values of the Iterable with the given serializer.
      Type Parameters:
      UK - Type of the keys
      UV - Type of the values
      Parameters:
      entries - Key-value pairs to serialize
      keySerializer - Serializer for UK
      valueSerializer - Serializer for UV
      Returns:
      Serialized values or null if values null or empty
      Throws:
      IOException - On failure during serialization
    • deserializeMap

      public static <UK, UV> Map<UK,UV> deserializeMap(byte[] serializedValue, org.apache.flink.api.common.typeutils.TypeSerializer<UK> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<UV> valueSerializer) throws IOException
      Deserializes all kv pairs with the given serializer.
      Type Parameters:
      UK - Type of the key
      UV - Type of the value.
      Parameters:
      serializedValue - Serialized value of type Map<UK, UV>
      keySerializer - Serializer for UK
      valueSerializer - Serializer for UV
      Returns:
      Deserialized map or null if the serialized value is null
      Throws:
      IOException - On failure during deserialization