2015-10-09 14:51:31 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-11-28 11:37:12 +00:00
|
|
|
#include <Common/config.h>
|
|
|
|
#if USE_POCO_MONGODB
|
2015-10-09 14:51:31 +00:00
|
|
|
|
2018-11-28 11:37:12 +00:00
|
|
|
#include "IDictionarySource.h"
|
|
|
|
#include "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
|
|
|
{
|
2017-04-01 07:20:54 +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
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
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,
|
|
|
|
const Block & sample_block);
|
2015-10-09 14:51:31 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
MongoDBDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct, const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & config_prefix, 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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadKeys(
|
2017-07-21 06:35:58 +00:00
|
|
|
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;
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2018-11-28 11:37:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*namespace DB
|
|
|
|
{
|
|
|
|
class DictionarySourceFactory;
|
|
|
|
void registerDictionarySourceMongoDB(DictionarySourceFactory & factory);
|
|
|
|
}*/
|