ClickHouse/dbms/include/DB/Dictionaries/MongoDBDictionarySource.h

74 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
#include <DB/Dictionaries/IDictionarySource.h>
2016-12-08 02:49:04 +00:00
#include <DB/Dictionaries/DictionaryStructure.h>
2016-12-08 02:49:04 +00:00
namespace Poco
{
2016-12-08 02:49:04 +00:00
namespace Util
{
class AbstractConfiguration;
}
namespace MongoDB
{
class Connection;
}
2016-01-12 02:21:15 +00:00
}
2016-12-08 02:49:04 +00:00
namespace DB
{
/// Allows loading dictionaries from a MongoDB collection
class MongoDBDictionarySource final : public IDictionarySource
{
MongoDBDictionarySource(
const DictionaryStructure & dict_struct, const std::string & host, UInt16 port,
const std::string & user, const std::string & password,
const std::string & method,
const std::string & db, const std::string & collection,
2016-12-08 02:49:04 +00:00
const Block & sample_block);
public:
MongoDBDictionarySource(
const DictionaryStructure & dict_struct, const Poco::Util::AbstractConfiguration & config,
2016-12-08 02:49:04 +00:00
const std::string & config_prefix, Block & sample_block);
2016-12-08 02:49:04 +00:00
MongoDBDictionarySource(const MongoDBDictionarySource & other);
2017-03-09 04:26:17 +00:00
~MongoDBDictionarySource() override;
2016-12-08 02:49:04 +00:00
BlockInputStreamPtr loadAll() override;
2016-12-08 02:49:04 +00:00
bool supportsSelectiveLoad() const override { return true; }
2016-12-08 02:49:04 +00:00
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
BlockInputStreamPtr loadKeys(
2016-12-08 02:49:04 +00:00
const ConstColumnPlainPtrs & key_columns, const std::vector<std::size_t> & requested_rows) override;
/// @todo: for MongoDB, modification date can somehow be determined from the `_id` object field
bool isModified() const override { return true; }
DictionarySourcePtr clone() const override { return std::make_unique<MongoDBDictionarySource>(*this); }
2016-12-08 02:49:04 +00:00
std::string toString() const override;
private:
const DictionaryStructure dict_struct;
const std::string host;
const UInt16 port;
const std::string user;
const std::string password;
const std::string method;
const std::string db;
const std::string collection;
Block sample_block;
std::shared_ptr<Poco::MongoDB::Connection> connection;
};
}