ClickHouse/src/Dictionaries/RedisDictionarySource.h

97 lines
2.4 KiB
C++
Raw Normal View History

2019-01-15 22:08:56 +00:00
#pragma once
2019-05-26 12:58:40 +00:00
#include <Core/Block.h>
#include "DictionaryStructure.h"
#include "IDictionarySource.h"
2019-01-15 22:08:56 +00:00
namespace Poco
{
namespace Util
{
class AbstractConfiguration;
}
namespace Redis
{
class Client;
class Array;
class Command;
2019-01-15 22:08:56 +00:00
}
}
namespace DB
{
2020-02-25 18:10:48 +00:00
namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
}
enum class RedisStorageType
2019-04-16 23:13:07 +00:00
{
SIMPLE,
HASH_MAP,
UNKNOWN
};
2019-04-16 23:13:07 +00:00
2019-01-15 22:08:56 +00:00
class RedisDictionarySource final : public IDictionarySource
{
RedisDictionarySource(
const DictionaryStructure & dict_struct,
const std::string & host,
UInt16 port,
UInt8 db_index,
const std::string & password,
RedisStorageType storage_type,
2019-01-15 22:08:56 +00:00
const Block & sample_block);
public:
using RedisArray = Poco::Redis::Array;
using RedisCommand = Poco::Redis::Command;
2019-01-15 22:08:56 +00:00
RedisDictionarySource(
const DictionaryStructure & dict_struct,
const Poco::Util::AbstractConfiguration & config,
const std::string & config_prefix,
Block & sample_block);
RedisDictionarySource(const RedisDictionarySource & other);
~RedisDictionarySource() override;
Pipe loadAll() override;
2019-01-15 22:08:56 +00:00
Pipe loadUpdatedAll() override
2019-01-15 22:08:56 +00:00
{
2021-04-10 18:48:36 +00:00
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method loadUpdatedAll is unsupported for RedisDictionarySource");
2019-01-15 22:08:56 +00:00
}
bool supportsSelectiveLoad() const override { return true; }
Pipe loadIds(const std::vector<UInt64> & ids) override;
2019-01-15 22:08:56 +00:00
Pipe loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
2019-01-15 22:08:56 +00:00
bool isModified() const override { return true; }
bool hasUpdateField() const override { return false; }
DictionarySourcePtr clone() const override { return std::make_unique<RedisDictionarySource>(*this); }
std::string toString() const override;
2019-04-16 23:13:07 +00:00
private:
static RedisStorageType parseStorageType(const std::string& storage_type);
2019-04-16 23:13:07 +00:00
2019-01-15 22:08:56 +00:00
const DictionaryStructure dict_struct;
const std::string host;
const UInt16 port;
const UInt8 db_index;
const std::string password;
const RedisStorageType storage_type;
2019-01-15 22:08:56 +00:00
Block sample_block;
std::shared_ptr<Poco::Redis::Client> client;
};
}