Java Code Examples for org.apache.flink.api.common.typeutils.base.MapSerializer#getKeySerializer()
The following examples show how to use
org.apache.flink.api.common.typeutils.base.MapSerializer#getKeySerializer() .
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: RocksDBMapState.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Creates a new {@code RocksDBMapState}. * * @param columnFamily The RocksDB column family that this state is associated to. * @param namespaceSerializer The serializer for the namespace. * @param valueSerializer The serializer for the state. * @param defaultValue The default value for the state. * @param backend The backend for which this state is bind to. */ private RocksDBMapState( ColumnFamilyHandle columnFamily, TypeSerializer<N> namespaceSerializer, TypeSerializer<Map<UK, UV>> valueSerializer, Map<UK, UV> defaultValue, RocksDBKeyedStateBackend<K> backend) { super(columnFamily, namespaceSerializer, valueSerializer, defaultValue, backend); Preconditions.checkState(valueSerializer instanceof MapSerializer, "Unexpected serializer type."); MapSerializer<UK, UV> castedMapSerializer = (MapSerializer<UK, UV>) valueSerializer; this.userKeySerializer = castedMapSerializer.getKeySerializer(); this.userValueSerializer = castedMapSerializer.getValueSerializer(); }
Example 2
Source File: RocksDBMapState.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a new {@code RocksDBMapState}. * * @param columnFamily The RocksDB column family that this state is associated to. * @param namespaceSerializer The serializer for the namespace. * @param valueSerializer The serializer for the state. * @param defaultValue The default value for the state. * @param backend The backend for which this state is bind to. */ private RocksDBMapState( ColumnFamilyHandle columnFamily, TypeSerializer<N> namespaceSerializer, TypeSerializer<Map<UK, UV>> valueSerializer, Map<UK, UV> defaultValue, RocksDBKeyedStateBackend<K> backend) { super(columnFamily, namespaceSerializer, valueSerializer, defaultValue, backend); Preconditions.checkState(valueSerializer instanceof MapSerializer, "Unexpected serializer type."); MapSerializer<UK, UV> castedMapSerializer = (MapSerializer<UK, UV>) valueSerializer; this.userKeySerializer = castedMapSerializer.getKeySerializer(); this.userValueSerializer = castedMapSerializer.getValueSerializer(); }
Example 3
Source File: RocksDBMapState.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a new {@code RocksDBMapState}. * * @param columnFamily The RocksDB column family that this state is associated to. * @param namespaceSerializer The serializer for the namespace. * @param valueSerializer The serializer for the state. * @param defaultValue The default value for the state. * @param backend The backend for which this state is bind to. */ private RocksDBMapState( ColumnFamilyHandle columnFamily, TypeSerializer<N> namespaceSerializer, TypeSerializer<Map<UK, UV>> valueSerializer, Map<UK, UV> defaultValue, RocksDBKeyedStateBackend<K> backend) { super(columnFamily, namespaceSerializer, valueSerializer, defaultValue, backend); Preconditions.checkState(valueSerializer instanceof MapSerializer, "Unexpected serializer type."); MapSerializer<UK, UV> castedMapSerializer = (MapSerializer<UK, UV>) valueSerializer; this.userKeySerializer = castedMapSerializer.getKeySerializer(); this.userValueSerializer = castedMapSerializer.getValueSerializer(); }
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: RocksDBKeyedStateBackend.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static <UK> boolean checkMapStateKeySchemaCompatibility( MapSerializerSnapshot<?, ?> mapStateSerializerSnapshot, MapSerializer<?, ?> newMapStateSerializer) { TypeSerializerSnapshot<UK> previousKeySerializerSnapshot = (TypeSerializerSnapshot<UK>) mapStateSerializerSnapshot.getKeySerializerSnapshot(); TypeSerializer<UK> newUserKeySerializer = (TypeSerializer<UK>) newMapStateSerializer.getKeySerializer(); TypeSerializerSchemaCompatibility<UK> keyCompatibility = previousKeySerializerSnapshot.resolveSchemaCompatibility(newUserKeySerializer); return keyCompatibility.isCompatibleAsIs(); }
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: AbstractMapStateReader.java From bravo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void configure(int maxParallelism, TypeSerializer<?> keySerializer, TypeSerializer<?> valueSerializer) throws Exception { if (valueSerializer instanceof MapSerializer) { MapSerializer<?, ?> mapSerializer = (MapSerializer<?, ?>) valueSerializer; if (mapKeytype == null && mapKeySerializer == null) { mapKeySerializer = (TypeSerializer<Object>) mapSerializer.getKeySerializer(); } super.configure(maxParallelism, keySerializer, mapSerializer.getValueSerializer()); } else { throw new RuntimeException("Doesnt seem like a map state"); } }
Example 8
Source File: RocksDBKeyedStateBackend.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static <UK> boolean checkMapStateKeySchemaCompatibility( MapSerializerSnapshot<?, ?> mapStateSerializerSnapshot, MapSerializer<?, ?> newMapStateSerializer) { TypeSerializerSnapshot<UK> previousKeySerializerSnapshot = (TypeSerializerSnapshot<UK>) mapStateSerializerSnapshot.getKeySerializerSnapshot(); TypeSerializer<UK> newUserKeySerializer = (TypeSerializer<UK>) newMapStateSerializer.getKeySerializer(); TypeSerializerSchemaCompatibility<UK> keyCompatibility = previousKeySerializerSnapshot.resolveSchemaCompatibility(newUserKeySerializer); return keyCompatibility.isCompatibleAsIs(); }
Example 9
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 10
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 11
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 12
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); }