2017-12-05 13:32:02 +00:00
|
|
|
#pragma once
|
2022-09-28 13:29:29 +00:00
|
|
|
#include "config.h"
|
2017-12-05 13:32:02 +00:00
|
|
|
|
2020-10-14 12:19:29 +00:00
|
|
|
#if USE_MYSQL
|
2017-12-05 13:32:02 +00:00
|
|
|
#include <TableFunctions/ITableFunction.h>
|
2021-09-03 11:16:32 +00:00
|
|
|
#include <Storages/ExternalDataSourceConfiguration.h>
|
2020-10-14 12:19:29 +00:00
|
|
|
#include <mysqlxx/Pool.h>
|
2017-12-05 13:32:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2017-12-26 21:34:06 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
/* mysql ('host:port', database, table, user, password) - creates a temporary StorageMySQL.
|
|
|
|
* The structure of the table is taken from the mysql query DESCRIBE table.
|
|
|
|
* If there is no such table, an exception is thrown.
|
|
|
|
*/
|
|
|
|
class TableFunctionMySQL : public ITableFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "mysql";
|
2017-12-26 18:32:17 +00:00
|
|
|
std::string getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2018-03-02 05:03:28 +00:00
|
|
|
private:
|
2021-04-10 23:33:54 +00:00
|
|
|
StoragePtr executeImpl(const ASTPtr & ast_function, ContextPtr context, const std::string & table_name, ColumnsDescription cached_columns) const override;
|
2020-04-06 05:19:40 +00:00
|
|
|
const char * getStorageTypeName() const override { return "MySQL"; }
|
2020-10-14 12:19:29 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
ColumnsDescription getActualTableStructure(ContextPtr context) const override;
|
|
|
|
void parseArguments(const ASTPtr & ast_function, ContextPtr context) override;
|
2020-10-14 12:19:29 +00:00
|
|
|
|
2021-03-24 18:15:31 +00:00
|
|
|
mutable std::optional<mysqlxx::PoolWithFailover> pool;
|
2021-09-03 11:16:32 +00:00
|
|
|
std::optional<StorageMySQLConfiguration> configuration;
|
2017-12-05 13:32:02 +00:00
|
|
|
};
|
2017-12-26 21:34:06 +00:00
|
|
|
|
2017-12-05 13:32:02 +00:00
|
|
|
}
|
2020-10-14 12:19:29 +00:00
|
|
|
|
|
|
|
#endif
|