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