2020-05-13 23:20:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-11-26 18:27:16 +00:00
|
|
|
#include <Poco/MongoDB/Connection.h>
|
|
|
|
|
2020-05-13 23:20:45 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2021-09-03 11:16:32 +00:00
|
|
|
#include <Storages/ExternalDataSourceConfiguration.h>
|
2020-06-26 14:28:00 +00:00
|
|
|
|
2020-05-13 23:20:45 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/* Implements storage in the MongoDB database.
|
|
|
|
* Use ENGINE = mysql(host_port, database_name, table_name, user_name, password)
|
|
|
|
* Read only.
|
|
|
|
*/
|
|
|
|
|
2022-05-03 06:43:28 +00:00
|
|
|
class StorageMongoDB final : public IStorage
|
2020-05-13 23:20:45 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
StorageMongoDB(
|
|
|
|
const StorageID & table_id_,
|
|
|
|
const std::string & host_,
|
2022-03-13 12:23:51 +00:00
|
|
|
uint16_t port_,
|
2020-05-13 23:20:45 +00:00
|
|
|
const std::string & database_name_,
|
|
|
|
const std::string & collection_name_,
|
|
|
|
const std::string & username_,
|
|
|
|
const std::string & password_,
|
2021-03-23 15:01:13 +00:00
|
|
|
const std::string & options_,
|
2020-05-13 23:20:45 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2021-04-23 12:18:23 +00:00
|
|
|
const ConstraintsDescription & constraints_,
|
|
|
|
const String & comment);
|
2020-05-13 23:20:45 +00:00
|
|
|
|
|
|
|
std::string getName() const override { return "MongoDB"; }
|
|
|
|
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe read(
|
2020-05-13 23:20:45 +00:00
|
|
|
const Names & column_names,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2020-05-13 23:20:45 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2021-09-03 11:16:32 +00:00
|
|
|
static StorageMongoDBConfiguration getConfiguration(ASTs engine_args, ContextPtr context);
|
|
|
|
|
2020-05-13 23:20:45 +00:00
|
|
|
private:
|
2021-02-05 08:47:02 +00:00
|
|
|
void connectIfNotConnected();
|
|
|
|
|
|
|
|
const std::string database_name;
|
|
|
|
const std::string collection_name;
|
|
|
|
const std::string username;
|
|
|
|
const std::string password;
|
2021-03-23 15:01:13 +00:00
|
|
|
const std::string uri;
|
2020-05-13 23:20:45 +00:00
|
|
|
|
|
|
|
std::shared_ptr<Poco::MongoDB::Connection> connection;
|
2021-06-28 17:02:22 +00:00
|
|
|
bool authenticated = false;
|
|
|
|
std::mutex connection_mutex; /// Protects the variables `connection` and `authenticated`.
|
2020-05-13 23:20:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|