def __init__(self, map_state_handler: CachingMapStateHandler, state_key, map_key_coder, map_value_coder, max_write_cache_entries): self._map_state_handler = map_state_handler self._state_key = state_key self._map_key_coder = map_key_coder if isinstance(map_key_coder, FieldCoder): map_key_coder_impl = FlinkCoder(map_key_coder).get_impl() else: map_key_coder_impl = map_key_coder.get_impl() self._map_key_encoder, self._map_key_decoder = \ self._get_encoder_and_decoder(map_key_coder_impl) self._map_value_coder = map_value_coder if isinstance(map_value_coder, FieldCoder): map_value_coder_impl = FlinkCoder(map_value_coder).get_impl() else: map_value_coder_impl = map_value_coder.get_impl() self._map_value_encoder, self._map_value_decoder = \ self._get_encoder_and_decoder(map_value_coder_impl) self._write_cache = dict() self._max_write_cache_entries = max_write_cache_entries self._is_empty = None self._cleared = False self._mod_count = 0
def _get_internal_bag_state(self, name, namespace, element_coder, ttl_config): encoded_namespace = self._encode_namespace(namespace) cached_state = self._internal_state_cache.get( (name, self._encoded_current_key, encoded_namespace)) if cached_state is not None: return cached_state # The created internal state would not be put into the internal state cache # at once. The internal state cache is only updated when the current key changes. # The reason is that the state cache size may be smaller that the count of activated # state (i.e. the state with current key). if isinstance(element_coder, FieldCoder): element_coder = FlinkCoder(element_coder) state_spec = userstate.BagStateSpec(name, element_coder) internal_state = self._create_bag_state(state_spec, encoded_namespace, ttl_config) return internal_state