2021-02-16 21:33:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Common/PODArray.h>
|
|
|
|
#include <Common/HashTable/HashMap.h>
|
|
|
|
#include <Columns/IColumn.h>
|
|
|
|
#include <Dictionaries/DictionaryHelpers.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-02-26 15:56:41 +00:00
|
|
|
struct KeyState
|
|
|
|
{
|
2021-03-03 18:58:43 +00:00
|
|
|
enum State: uint8_t
|
2021-02-26 15:56:41 +00:00
|
|
|
{
|
2021-03-03 18:58:43 +00:00
|
|
|
not_found = 2,
|
|
|
|
expired = 4,
|
|
|
|
found = 8,
|
2021-02-26 15:56:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
KeyState(State state_, size_t fetched_column_index_)
|
|
|
|
: state(state_)
|
|
|
|
, fetched_column_index(fetched_column_index_)
|
|
|
|
{}
|
|
|
|
|
|
|
|
KeyState(State state_)
|
|
|
|
: state(state_)
|
|
|
|
{}
|
|
|
|
|
|
|
|
inline bool isFound() const { return state == State::found; }
|
|
|
|
inline bool isExpired() const { return state == State::expired; }
|
|
|
|
inline bool isNotFound() const { return state == State::not_found; }
|
2021-03-03 18:58:43 +00:00
|
|
|
inline bool isDefault() const { return is_default; }
|
|
|
|
inline void setDefault() { is_default = true; }
|
2021-03-13 21:49:45 +00:00
|
|
|
inline void setDefaultValue(bool is_default_value) { is_default = is_default_value; }
|
2021-03-04 14:34:39 +00:00
|
|
|
/// Valid only if keyState is found or expired
|
2021-03-03 18:58:43 +00:00
|
|
|
inline size_t getFetchedColumnIndex() const { return fetched_column_index; }
|
2021-02-26 15:56:41 +00:00
|
|
|
|
2021-03-03 18:58:43 +00:00
|
|
|
private:
|
2021-02-26 15:56:41 +00:00
|
|
|
State state = not_found;
|
|
|
|
size_t fetched_column_index = 0;
|
2021-03-03 18:58:43 +00:00
|
|
|
bool is_default = false;
|
2021-02-26 15:56:41 +00:00
|
|
|
};
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Result of fetch from CacheDictionaryStorage
|
2021-02-16 21:33:02 +00:00
|
|
|
template <typename KeyType>
|
|
|
|
struct KeysStorageFetchResult
|
|
|
|
{
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Fetched column values
|
2021-02-16 21:33:02 +00:00
|
|
|
MutableColumns fetched_columns;
|
|
|
|
|
2021-02-26 15:56:41 +00:00
|
|
|
PaddedPODArray<KeyState> key_index_to_state;
|
2021-02-16 21:33:02 +00:00
|
|
|
|
2021-02-26 15:56:41 +00:00
|
|
|
size_t expired_keys_size = 0;
|
2021-02-16 21:33:02 +00:00
|
|
|
|
2021-02-26 15:56:41 +00:00
|
|
|
size_t found_keys_size = 0;
|
2021-02-16 21:33:02 +00:00
|
|
|
|
2021-02-26 15:56:41 +00:00
|
|
|
size_t not_found_keys_size = 0;
|
2021-02-16 21:33:02 +00:00
|
|
|
|
2021-03-03 18:58:43 +00:00
|
|
|
size_t default_keys_size = 0;
|
|
|
|
|
2021-02-16 21:33:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using SimpleKeysStorageFetchResult = KeysStorageFetchResult<UInt64>;
|
|
|
|
using ComplexKeysStorageFetchResult = KeysStorageFetchResult<StringRef>;
|
|
|
|
|
|
|
|
class ICacheDictionaryStorage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~ICacheDictionaryStorage() = default;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Necessary if all keys are found we can return result to client without additional aggregation
|
2021-02-17 18:19:04 +00:00
|
|
|
virtual bool returnsFetchedColumnsInOrderOfRequestedKeys() const = 0;
|
2021-02-17 11:48:06 +00:00
|
|
|
|
2021-02-26 15:56:41 +00:00
|
|
|
/// Name of storage
|
|
|
|
virtual String getName() const = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Does storage support simple keys
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual bool supportsSimpleKeys() const = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Fetch columns for keys, this method is not write thread safe
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual SimpleKeysStorageFetchResult fetchColumnsForKeys(
|
|
|
|
const PaddedPODArray<UInt64> & keys,
|
2021-02-17 11:48:06 +00:00
|
|
|
const DictionaryStorageFetchRequest & fetch_request) = 0;
|
2021-02-16 21:33:02 +00:00
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Fetch columns for keys, this method is not write thread safe
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual void insertColumnsForKeys(const PaddedPODArray<UInt64> & keys, Columns columns) = 0;
|
|
|
|
|
2021-03-03 18:58:43 +00:00
|
|
|
/// Insert default keys
|
|
|
|
virtual void insertDefaultKeys(const PaddedPODArray<UInt64> & keys) = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Return cached simple keys
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual PaddedPODArray<UInt64> getCachedSimpleKeys() const = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Does storage support complex keys
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual bool supportsComplexKeys() const = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Fetch columns for keys, this method is not write thread safe
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual ComplexKeysStorageFetchResult fetchColumnsForKeys(
|
|
|
|
const PaddedPODArray<StringRef> & keys,
|
2021-02-17 11:48:06 +00:00
|
|
|
const DictionaryStorageFetchRequest & column_fetch_requests) = 0;
|
2021-02-16 21:33:02 +00:00
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Fetch columns for keys, this method is not write thread safe
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual void insertColumnsForKeys(const PaddedPODArray<StringRef> & keys, Columns columns) = 0;
|
|
|
|
|
2021-03-03 18:58:43 +00:00
|
|
|
/// Insert default keys
|
|
|
|
virtual void insertDefaultKeys(const PaddedPODArray<StringRef> & keys) = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Return cached simple keys
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual PaddedPODArray<StringRef> getCachedComplexKeys() const = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Return size of keys in storage
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual size_t getSize() const = 0;
|
|
|
|
|
2021-02-17 18:19:04 +00:00
|
|
|
/// Return maximum size of keys in storage
|
|
|
|
virtual size_t getMaxSize() const = 0;
|
|
|
|
|
2021-02-17 11:48:06 +00:00
|
|
|
/// Return bytes allocated in storage
|
2021-02-16 21:33:02 +00:00
|
|
|
virtual size_t getBytesAllocated() const = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
using CacheDictionaryStoragePtr = std::shared_ptr<ICacheDictionaryStorage>;
|
|
|
|
|
|
|
|
}
|