Java Code Examples for org.apache.flink.queryablestate.client.state.serialization.KvStateSerializer#serializeMap()
The following examples show how to use
org.apache.flink.queryablestate.client.state.serialization.KvStateSerializer#serializeMap() .
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: ImmutableMapStateTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { if (!mapStateDesc.isSerializerInitialized()) { mapStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); } Map<Long, Long> initMap = new HashMap<>(); initMap.put(1L, 5L); initMap.put(2L, 5L); byte[] initSer = KvStateSerializer.serializeMap( initMap.entrySet(), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig()), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig())); mapState = ImmutableMapState.createState(mapStateDesc, initSer); }
Example 2
Source File: ImmutableMapStateTest.java From flink with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { if (!mapStateDesc.isSerializerInitialized()) { mapStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); } Map<Long, Long> initMap = new HashMap<>(); initMap.put(1L, 5L); initMap.put(2L, 5L); byte[] initSer = KvStateSerializer.serializeMap( initMap.entrySet(), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig()), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig())); mapState = ImmutableMapState.createState(mapStateDesc, initSer); }
Example 3
Source File: ImmutableMapStateTest.java From flink with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { if (!mapStateDesc.isSerializerInitialized()) { mapStateDesc.initializeSerializerUnlessSet(new ExecutionConfig()); } Map<Long, Long> initMap = new HashMap<>(); initMap.put(1L, 5L); initMap.put(2L, 5L); byte[] initSer = KvStateSerializer.serializeMap( initMap.entrySet(), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig()), BasicTypeInfo.LONG_TYPE_INFO.createSerializer(new ExecutionConfig())); mapState = ImmutableMapState.createState(mapStateDesc, initSer); }
Example 4
Source File: HeapMapState.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<Map<UK, UV>> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); Map<UK, UV> result = stateTable.get(keyAndNamespace.f0, keyAndNamespace.f1); if (result == null) { return null; } final MapSerializer<UK, UV> serializer = (MapSerializer<UK, UV>) safeValueSerializer; final TypeSerializer<UK> dupUserKeySerializer = serializer.getKeySerializer(); final TypeSerializer<UV> dupUserValueSerializer = serializer.getValueSerializer(); return KvStateSerializer.serializeMap(result.entrySet(), dupUserKeySerializer, dupUserValueSerializer); }
Example 5
Source File: HeapMapState.java From flink with Apache License 2.0 | 5 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<Map<UK, UV>> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); Map<UK, UV> result = stateTable.get(keyAndNamespace.f0, keyAndNamespace.f1); if (result == null) { return null; } final MapSerializer<UK, UV> serializer = (MapSerializer<UK, UV>) safeValueSerializer; final TypeSerializer<UK> dupUserKeySerializer = serializer.getKeySerializer(); final TypeSerializer<UV> dupUserValueSerializer = serializer.getValueSerializer(); return KvStateSerializer.serializeMap(result.entrySet(), dupUserKeySerializer, dupUserValueSerializer); }
Example 6
Source File: HeapMapState.java From flink with Apache License 2.0 | 5 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<Map<UK, UV>> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); Map<UK, UV> result = stateTable.get(keyAndNamespace.f0, keyAndNamespace.f1); if (result == null) { return null; } final MapSerializer<UK, UV> serializer = (MapSerializer<UK, UV>) safeValueSerializer; final TypeSerializer<UK> dupUserKeySerializer = serializer.getKeySerializer(); final TypeSerializer<UV> dupUserValueSerializer = serializer.getValueSerializer(); return KvStateSerializer.serializeMap(result.entrySet(), dupUserKeySerializer, dupUserValueSerializer); }
Example 7
Source File: RocksDBMapState.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<Map<UK, UV>> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); //TODO make KvStateSerializer key-group aware to save this round trip and key-group computation Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(keyAndNamespace.f0, backend.getNumberOfKeyGroups()); RocksDBSerializedCompositeKeyBuilder<K> keyBuilder = new RocksDBSerializedCompositeKeyBuilder<>( safeKeySerializer, backend.getKeyGroupPrefixBytes(), 32); keyBuilder.setKeyAndKeyGroup(keyAndNamespace.f0, keyGroup); final byte[] keyPrefixBytes = keyBuilder.buildCompositeKeyNamespace(keyAndNamespace.f1, namespaceSerializer); final MapSerializer<UK, UV> serializer = (MapSerializer<UK, UV>) safeValueSerializer; final TypeSerializer<UK> dupUserKeySerializer = serializer.getKeySerializer(); final TypeSerializer<UV> dupUserValueSerializer = serializer.getValueSerializer(); final DataInputDeserializer inputView = new DataInputDeserializer(); final Iterator<Map.Entry<UK, UV>> iterator = new RocksDBMapIterator<Map.Entry<UK, UV>>( backend.db, keyPrefixBytes, dupUserKeySerializer, dupUserValueSerializer, inputView ) { @Override public Map.Entry<UK, UV> next() { return nextEntry(); } }; // Return null to make the behavior consistent with other backends if (!iterator.hasNext()) { return null; } return KvStateSerializer.serializeMap(() -> iterator, dupUserKeySerializer, dupUserValueSerializer); }
Example 8
Source File: RocksDBMapState.java From flink with Apache License 2.0 | 4 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<Map<UK, UV>> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); //TODO make KvStateSerializer key-group aware to save this round trip and key-group computation Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(keyAndNamespace.f0, backend.getNumberOfKeyGroups()); RocksDBSerializedCompositeKeyBuilder<K> keyBuilder = new RocksDBSerializedCompositeKeyBuilder<>( safeKeySerializer, backend.getKeyGroupPrefixBytes(), 32); keyBuilder.setKeyAndKeyGroup(keyAndNamespace.f0, keyGroup); final byte[] keyPrefixBytes = keyBuilder.buildCompositeKeyNamespace(keyAndNamespace.f1, namespaceSerializer); final MapSerializer<UK, UV> serializer = (MapSerializer<UK, UV>) safeValueSerializer; final TypeSerializer<UK> dupUserKeySerializer = serializer.getKeySerializer(); final TypeSerializer<UV> dupUserValueSerializer = serializer.getValueSerializer(); final DataInputDeserializer inputView = new DataInputDeserializer(); final Iterator<Map.Entry<UK, UV>> iterator = new RocksDBMapIterator<Map.Entry<UK, UV>>( backend.db, keyPrefixBytes, dupUserKeySerializer, dupUserValueSerializer, inputView ) { @Override public Map.Entry<UK, UV> next() { return nextEntry(); } }; // Return null to make the behavior consistent with other backends if (!iterator.hasNext()) { return null; } return KvStateSerializer.serializeMap(() -> iterator, dupUserKeySerializer, dupUserValueSerializer); }
Example 9
Source File: RocksDBMapState.java From flink with Apache License 2.0 | 4 votes |
@Override public byte[] getSerializedValue( final byte[] serializedKeyAndNamespace, final TypeSerializer<K> safeKeySerializer, final TypeSerializer<N> safeNamespaceSerializer, final TypeSerializer<Map<UK, UV>> safeValueSerializer) throws Exception { Preconditions.checkNotNull(serializedKeyAndNamespace); Preconditions.checkNotNull(safeKeySerializer); Preconditions.checkNotNull(safeNamespaceSerializer); Preconditions.checkNotNull(safeValueSerializer); //TODO make KvStateSerializer key-group aware to save this round trip and key-group computation Tuple2<K, N> keyAndNamespace = KvStateSerializer.deserializeKeyAndNamespace( serializedKeyAndNamespace, safeKeySerializer, safeNamespaceSerializer); int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(keyAndNamespace.f0, backend.getNumberOfKeyGroups()); RocksDBSerializedCompositeKeyBuilder<K> keyBuilder = new RocksDBSerializedCompositeKeyBuilder<>( safeKeySerializer, backend.getKeyGroupPrefixBytes(), 32); keyBuilder.setKeyAndKeyGroup(keyAndNamespace.f0, keyGroup); final byte[] keyPrefixBytes = keyBuilder.buildCompositeKeyNamespace(keyAndNamespace.f1, namespaceSerializer); final MapSerializer<UK, UV> serializer = (MapSerializer<UK, UV>) safeValueSerializer; final TypeSerializer<UK> dupUserKeySerializer = serializer.getKeySerializer(); final TypeSerializer<UV> dupUserValueSerializer = serializer.getValueSerializer(); final DataInputDeserializer inputView = new DataInputDeserializer(); final Iterator<Map.Entry<UK, UV>> iterator = new RocksDBMapIterator<Map.Entry<UK, UV>>( backend.db, keyPrefixBytes, dupUserKeySerializer, dupUserValueSerializer, inputView ) { @Override public Map.Entry<UK, UV> next() { return nextEntry(); } }; // Return null to make the behavior consistent with other backends if (!iterator.hasNext()) { return null; } return KvStateSerializer.serializeMap(() -> iterator, dupUserKeySerializer, dupUserValueSerializer); }