2019-01-15 22:08:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Common/config.h>
|
2019-05-26 12:58:40 +00:00
|
|
|
#include <Core/Block.h>
|
2019-01-15 22:08:56 +00:00
|
|
|
#if USE_POCO_REDIS
|
|
|
|
|
|
|
|
# include "DictionaryStructure.h"
|
|
|
|
# include "IDictionarySource.h"
|
|
|
|
|
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Redis
|
|
|
|
{
|
|
|
|
class Client;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-04-16 23:13:07 +00:00
|
|
|
namespace RedisStorageType
|
|
|
|
{
|
|
|
|
enum Id
|
|
|
|
{
|
|
|
|
SIMPLE,
|
|
|
|
HASH_MAP,
|
|
|
|
UNKNOWN
|
|
|
|
};
|
|
|
|
|
2019-05-26 12:58:40 +00:00
|
|
|
Id valueOf(const std::string & value)
|
2019-04-16 23:13:07 +00:00
|
|
|
{
|
|
|
|
if (value == "simple")
|
|
|
|
return SIMPLE;
|
|
|
|
if (value == "hash_map")
|
|
|
|
return HASH_MAP;
|
|
|
|
return UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 22:08:56 +00:00
|
|
|
class RedisDictionarySource final : public IDictionarySource
|
|
|
|
{
|
|
|
|
RedisDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct,
|
|
|
|
const std::string & host,
|
|
|
|
UInt16 port,
|
2019-04-14 17:05:50 +00:00
|
|
|
UInt8 db_index,
|
2019-04-16 23:13:07 +00:00
|
|
|
RedisStorageType::Id storage_type,
|
2019-01-15 22:08:56 +00:00
|
|
|
const Block & sample_block);
|
|
|
|
|
|
|
|
public:
|
|
|
|
RedisDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct,
|
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & config_prefix,
|
|
|
|
Block & sample_block);
|
|
|
|
|
|
|
|
RedisDictionarySource(const RedisDictionarySource & other);
|
|
|
|
|
|
|
|
~RedisDictionarySource() override;
|
|
|
|
|
|
|
|
BlockInputStreamPtr loadAll() override;
|
|
|
|
|
|
|
|
BlockInputStreamPtr loadUpdatedAll() override
|
|
|
|
{
|
|
|
|
throw Exception{"Method loadUpdatedAll is unsupported for RedisDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool supportsSelectiveLoad() const override { return true; }
|
|
|
|
|
2019-01-27 13:14:02 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
|
2019-01-15 22:08:56 +00:00
|
|
|
|
2019-01-27 13:14:02 +00:00
|
|
|
BlockInputStreamPtr loadKeys(const Columns & /* key_columns */, const std::vector<size_t> & /* requested_rows */) override
|
|
|
|
{
|
2019-04-16 23:13:07 +00:00
|
|
|
// Redis does not support native indexing
|
2019-01-27 13:14:02 +00:00
|
|
|
throw Exception{"Method loadKeys is unsupported for RedisDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
2019-02-13 00:05:43 +00:00
|
|
|
}
|
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::Id parseStorageType(const std::string& storage_type);
|
|
|
|
|
2019-01-15 22:08:56 +00:00
|
|
|
private:
|
|
|
|
const DictionaryStructure dict_struct;
|
|
|
|
const std::string host;
|
|
|
|
const UInt16 port;
|
2019-04-14 17:05:50 +00:00
|
|
|
const UInt8 db_index; // [0..15]
|
2019-04-16 23:13:07 +00:00
|
|
|
const RedisStorageType::Id storage_type;
|
2019-01-15 22:08:56 +00:00
|
|
|
Block sample_block;
|
|
|
|
|
|
|
|
std::shared_ptr<Poco::Redis::Client> client;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|