2017-12-05 13:32:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-12-27 21:45:05 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <mysqlxx/Pool.h>
|
|
|
|
|
2017-12-13 16:46:57 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-26 21:34:06 +00:00
|
|
|
/** Implements storage in the MySQL database.
|
|
|
|
* Use ENGINE = mysql(host_port, database_name, table_name, user_name, password)
|
|
|
|
* Read only.
|
|
|
|
*/
|
2017-12-27 21:45:05 +00:00
|
|
|
class StorageMySQL : public ext::shared_ptr_helper<StorageMySQL>, public IStorage
|
2017-12-05 13:32:02 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-12-26 21:34:06 +00:00
|
|
|
StorageMySQL(
|
|
|
|
const std::string & name,
|
|
|
|
const std::string & host,
|
|
|
|
UInt16 port,
|
|
|
|
const std::string & remote_database_name,
|
|
|
|
const std::string & remote_table_name,
|
|
|
|
const std::string & user,
|
2017-12-05 13:32:02 +00:00
|
|
|
const std::string & password,
|
2017-12-26 21:34:06 +00:00
|
|
|
const NamesAndTypesList & columns);
|
2017-12-05 13:32:02 +00:00
|
|
|
|
2017-12-26 21:34:06 +00:00
|
|
|
std::string getName() const override { return "MySQL"; }
|
|
|
|
std::string getTableName() const override { return name; }
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return columns; }
|
2017-12-05 13:32:02 +00:00
|
|
|
|
2017-12-26 21:34:06 +00:00
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-12-05 13:32:02 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
|
|
|
|
|
|
|
private:
|
2017-12-26 21:34:06 +00:00
|
|
|
std::string name;
|
|
|
|
|
|
|
|
std::string remote_database_name;
|
|
|
|
std::string remote_table_name;
|
|
|
|
|
|
|
|
NamesAndTypesList columns;
|
2017-12-05 13:32:02 +00:00
|
|
|
mysqlxx::Pool pool;
|
|
|
|
};
|
2017-12-26 21:34:06 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
}
|