2015-10-09 14:51:31 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Core/Block.h>
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2020-05-08 14:11:19 +00:00
|
|
|
#include "DictionaryStructure.h"
|
|
|
|
#include "IDictionarySource.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
|
|
|
{
|
2018-12-10 15:25:45 +00:00
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
namespace MongoDB
|
|
|
|
{
|
|
|
|
class Connection;
|
|
|
|
}
|
2016-01-12 02:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-25 18:10:48 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
2020-02-25 18:20:08 +00:00
|
|
|
|
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
|
|
|
|
{
|
2020-05-14 11:36:19 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
MongoDBDictionarySource(
|
2019-08-03 11:02:40 +00:00
|
|
|
const DictionaryStructure & dict_struct_,
|
2020-05-14 11:36:19 +00:00
|
|
|
const std::string & uri_,
|
2019-08-03 11:02:40 +00:00
|
|
|
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_,
|
|
|
|
const Block & sample_block_);
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
MongoDBDictionarySource(const MongoDBDictionarySource & other);
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~MongoDBDictionarySource() override;
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2015-11-12 14:28:23 +00:00
|
|
|
|
2018-02-15 13:08:23 +00:00
|
|
|
BlockInputStreamPtr loadUpdatedAll() override
|
|
|
|
{
|
|
|
|
throw Exception{"Method loadUpdatedAll is unsupported for MongoDBDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool supportsSelectiveLoad() const override { return true; }
|
2015-10-13 12:17:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
|
2015-11-16 17:27:12 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// @todo: for MongoDB, modification date can somehow be determined from the `_id` object field
|
|
|
|
bool isModified() const override { return true; }
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2018-01-15 12:44:39 +00:00
|
|
|
///Not yet supported
|
|
|
|
bool hasUpdateField() const override { return false; }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DictionarySourcePtr clone() const override { return std::make_unique<MongoDBDictionarySource>(*this); }
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string toString() const override;
|
2015-10-09 14:51:31 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
const DictionaryStructure dict_struct;
|
2020-05-14 11:36:19 +00:00
|
|
|
const std::string uri;
|
2017-04-01 07:20:54 +00:00
|
|
|
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;
|
2015-10-09 14:51:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|