ClickHouse/src/Dictionaries/ICacheDictionaryStorage.h

83 lines
2.6 KiB
C++
Raw Normal View History

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-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-17 11:48:06 +00:00
/// Found key to index in fetched_columns
2021-02-16 21:33:02 +00:00
HashMap<KeyType, size_t> found_keys_to_fetched_columns_index;
2021-02-17 11:48:06 +00:00
/// Expired key to index in fetched_columns
2021-02-16 21:33:02 +00:00
HashMap<KeyType, size_t> expired_keys_to_fetched_columns_index;
2021-02-17 11:48:06 +00:00
/// Keys that are not found in storage
2021-02-16 21:33:02 +00:00
PaddedPODArray<KeyType> not_found_or_expired_keys;
2021-02-17 11:48:06 +00:00
/// Indexes of requested keys that are not found in storage
2021-02-16 21:33:02 +00:00
PaddedPODArray<size_t> not_found_or_expired_keys_indexes;
};
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
virtual bool returnFetchedColumnsDuringFetchInOrderOfRequestedKeys() const = 0;
/// 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-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-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 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>;
}