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;
|
2020-05-13 23:20:45 +00:00
|
|
|
class Cursor;
|
2018-12-10 15:25:45 +00:00
|
|
|
}
|
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
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe loadAll() override;
|
2015-11-12 14:28:23 +00:00
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe loadUpdatedAll() override
|
2018-02-15 13:08:23 +00:00
|
|
|
{
|
2021-04-10 18:48:36 +00:00
|
|
|
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method loadUpdatedAll is unsupported for MongoDBDictionarySource");
|
2018-02-15 13:08:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool supportsSelectiveLoad() const override { return true; }
|
2015-10-13 12:17:09 +00:00
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe loadIds(const std::vector<UInt64> & ids) override;
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe 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; }
|
|
|
|
|
2021-12-15 12:55:28 +00:00
|
|
|
DictionarySourcePtr clone() const override { return std::make_shared<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;
|
2020-05-19 20:12:10 +00:00
|
|
|
std::string host;
|
|
|
|
UInt16 port;
|
|
|
|
std::string user;
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string password;
|
|
|
|
const std::string method;
|
2020-05-19 20:12:10 +00:00
|
|
|
std::string db;
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string collection;
|
|
|
|
Block sample_block;
|
|
|
|
|
|
|
|
std::shared_ptr<Poco::MongoDB::Connection> connection;
|
2015-10-09 14:51:31 +00:00
|
|
|
};
|
|
|
|
|
2021-08-06 08:41:45 +00:00
|
|
|
}
|