ClickHouse/src/Dictionaries/MongoDBDictionarySource.h

88 lines
2.1 KiB
C++
Raw Normal View History

#pragma once
#include <Core/Block.h>
#include "DictionaryStructure.h"
#include "IDictionarySource.h"
2016-12-08 02:49:04 +00:00
namespace Poco
{
namespace Util
{
class AbstractConfiguration;
}
namespace MongoDB
{
class Connection;
2020-05-13 23:20:45 +00:00
class Cursor;
}
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
/// Allows loading dictionaries from a MongoDB collection
class MongoDBDictionarySource final : public IDictionarySource
{
2020-05-14 11:36:19 +00:00
public:
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_);
MongoDBDictionarySource(const MongoDBDictionarySource & other);
~MongoDBDictionarySource() override;
Pipe loadAll() override;
Pipe loadUpdatedAll() override
{
2021-04-10 18:48:36 +00:00
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method loadUpdatedAll is unsupported for MongoDBDictionarySource");
}
bool supportsSelectiveLoad() const override { return true; }
Pipe loadIds(const std::vector<UInt64> & ids) override;
Pipe loadKeys(const Columns & key_columns, const std::vector<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; }
///Not yet supported
bool hasUpdateField() const override { return false; }
DictionarySourcePtr clone() const override { return std::make_shared<MongoDBDictionarySource>(*this); }
std::string toString() const override;
private:
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;
const std::string password;
const std::string method;
2020-05-19 20:12:10 +00:00
std::string db;
const std::string collection;
Block sample_block;
std::shared_ptr<Poco::MongoDB::Connection> connection;
};
}