Java Code Examples for org.apache.flink.queryablestate.client.state.serialization.KvStateSerializer#serializeValue()
The following examples show how to use
org.apache.flink.queryablestate.client.state.serialization.KvStateSerializer#serializeValue() .
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: AbstractHeapState.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<SV> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); SV result = stateTable.get(keyAndNamespace.f0, keyAndNamespace.f1); if (result == null) { return null; } return KvStateSerializer.serializeValue(result, safeValueSerializer); }
Example 2
Source File: AbstractHeapState.java From flink with Apache License 2.0 | 6 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<SV> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); SV result = stateTable.get(keyAndNamespace.f0, keyAndNamespace.f1); if (result == null) { return null; } return KvStateSerializer.serializeValue(result, safeValueSerializer); }
Example 3
Source File: AbstractHeapState.java From flink with Apache License 2.0 | 6 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<SV> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); SV result = stateTable.get(keyAndNamespace.f0, keyAndNamespace.f1); if (result == null) { return null; } return KvStateSerializer.serializeValue(result, safeValueSerializer); }
Example 4
Source File: KvStateRequestSerializerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests value serialization utils. */ @Test public void testValueSerialization() throws Exception { TypeSerializer<Long> valueSerializer = LongSerializer.INSTANCE; long expectedValue = Long.MAX_VALUE - 1292929292L; byte[] serializedValue = KvStateSerializer.serializeValue(expectedValue, valueSerializer); long actualValue = KvStateSerializer.deserializeValue(serializedValue, valueSerializer); assertEquals(expectedValue, actualValue); }
Example 5
Source File: KvStateRequestSerializerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Verifies that the serialization of a list using the given list state * matches the deserialization with {@link KvStateSerializer#deserializeList}. * * @param key * key of the list state * @param listState * list state using the {@link VoidNamespace}, must also be a {@link InternalKvState} instance * * @throws Exception */ public static void testListSerialization( final long key, final InternalListState<Long, VoidNamespace, Long> listState) throws Exception { TypeSerializer<Long> valueSerializer = LongSerializer.INSTANCE; listState.setCurrentNamespace(VoidNamespace.INSTANCE); // List final int numElements = 10; final List<Long> expectedValues = new ArrayList<>(); for (int i = 0; i < numElements; i++) { final long value = ThreadLocalRandom.current().nextLong(); expectedValues.add(value); listState.add(value); } final byte[] serializedKey = KvStateSerializer.serializeKeyAndNamespace( key, LongSerializer.INSTANCE, VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE); final byte[] serializedValues = listState.getSerializedValue( serializedKey, listState.getKeySerializer(), listState.getNamespaceSerializer(), listState.getValueSerializer()); List<Long> actualValues = KvStateSerializer.deserializeList(serializedValues, valueSerializer); assertEquals(expectedValues, actualValues); // Single value long expectedValue = ThreadLocalRandom.current().nextLong(); byte[] serializedValue = KvStateSerializer.serializeValue(expectedValue, valueSerializer); List<Long> actualValue = KvStateSerializer.deserializeList(serializedValue, valueSerializer); assertEquals(1, actualValue.size()); assertEquals(expectedValue, actualValue.get(0).longValue()); }
Example 6
Source File: KvStateRequestSerializerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests value serialization utils. */ @Test public void testValueSerialization() throws Exception { TypeSerializer<Long> valueSerializer = LongSerializer.INSTANCE; long expectedValue = Long.MAX_VALUE - 1292929292L; byte[] serializedValue = KvStateSerializer.serializeValue(expectedValue, valueSerializer); long actualValue = KvStateSerializer.deserializeValue(serializedValue, valueSerializer); assertEquals(expectedValue, actualValue); }
Example 7
Source File: KvStateRequestSerializerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verifies that the serialization of a list using the given list state * matches the deserialization with {@link KvStateSerializer#deserializeList}. * * @param key * key of the list state * @param listState * list state using the {@link VoidNamespace}, must also be a {@link InternalKvState} instance * * @throws Exception */ public static void testListSerialization( final long key, final InternalListState<Long, VoidNamespace, Long> listState) throws Exception { TypeSerializer<Long> valueSerializer = LongSerializer.INSTANCE; listState.setCurrentNamespace(VoidNamespace.INSTANCE); // List final int numElements = 10; final List<Long> expectedValues = new ArrayList<>(); for (int i = 0; i < numElements; i++) { final long value = ThreadLocalRandom.current().nextLong(); expectedValues.add(value); listState.add(value); } final byte[] serializedKey = KvStateSerializer.serializeKeyAndNamespace( key, LongSerializer.INSTANCE, VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE); final byte[] serializedValues = listState.getSerializedValue( serializedKey, listState.getKeySerializer(), listState.getNamespaceSerializer(), listState.getValueSerializer()); List<Long> actualValues = KvStateSerializer.deserializeList(serializedValues, valueSerializer); assertEquals(expectedValues, actualValues); // Single value long expectedValue = ThreadLocalRandom.current().nextLong(); byte[] serializedValue = KvStateSerializer.serializeValue(expectedValue, valueSerializer); List<Long> actualValue = KvStateSerializer.deserializeList(serializedValue, valueSerializer); assertEquals(1, actualValue.size()); assertEquals(expectedValue, actualValue.get(0).longValue()); }
Example 8
Source File: KvStateRequestSerializerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests value serialization utils. */ @Test public void testValueSerialization() throws Exception { TypeSerializer<Long> valueSerializer = LongSerializer.INSTANCE; long expectedValue = Long.MAX_VALUE - 1292929292L; byte[] serializedValue = KvStateSerializer.serializeValue(expectedValue, valueSerializer); long actualValue = KvStateSerializer.deserializeValue(serializedValue, valueSerializer); assertEquals(expectedValue, actualValue); }
Example 9
Source File: KvStateRequestSerializerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verifies that the serialization of a list using the given list state * matches the deserialization with {@link KvStateSerializer#deserializeList}. * * @param key * key of the list state * @param listState * list state using the {@link VoidNamespace}, must also be a {@link InternalKvState} instance * * @throws Exception */ public static void testListSerialization( final long key, final InternalListState<Long, VoidNamespace, Long> listState) throws Exception { TypeSerializer<Long> valueSerializer = LongSerializer.INSTANCE; listState.setCurrentNamespace(VoidNamespace.INSTANCE); // List final int numElements = 10; final List<Long> expectedValues = new ArrayList<>(); for (int i = 0; i < numElements; i++) { final long value = ThreadLocalRandom.current().nextLong(); expectedValues.add(value); listState.add(value); } final byte[] serializedKey = KvStateSerializer.serializeKeyAndNamespace( key, LongSerializer.INSTANCE, VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE); final byte[] serializedValues = listState.getSerializedValue( serializedKey, listState.getKeySerializer(), listState.getNamespaceSerializer(), listState.getValueSerializer()); List<Long> actualValues = KvStateSerializer.deserializeList(serializedValues, valueSerializer); assertEquals(expectedValues, actualValues); // Single value long expectedValue = ThreadLocalRandom.current().nextLong(); byte[] serializedValue = KvStateSerializer.serializeValue(expectedValue, valueSerializer); List<Long> actualValue = KvStateSerializer.deserializeList(serializedValue, valueSerializer); assertEquals(1, actualValue.size()); assertEquals(expectedValue, actualValue.get(0).longValue()); }