2018-09-25 00:21:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
#include <Storages/StorageXDBC.h>
|
2018-09-25 00:21:20 +00:00
|
|
|
#include <TableFunctions/ITableFunction.h>
|
2020-01-26 09:49:53 +00:00
|
|
|
#include <Access/AccessFlags.h>
|
2018-09-25 00:21:20 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2018-10-03 10:44:43 +00:00
|
|
|
#include <Common/XDBCBridgeHelper.h>
|
|
|
|
#include <Common/config.h>
|
2018-09-25 00:21:20 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Base class for table functions, that works over external bridge
|
|
|
|
* Xdbc (Xdbc connect string, table) - creates a temporary StorageXDBC.
|
|
|
|
*/
|
|
|
|
class ITableFunctionXDBC : public ITableFunction
|
|
|
|
{
|
|
|
|
private:
|
2019-07-18 18:29:49 +00:00
|
|
|
StoragePtr executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const override;
|
2018-09-25 00:21:20 +00:00
|
|
|
|
|
|
|
/* A factory method to create bridge helper, that will assist in remote interaction */
|
2018-11-22 15:59:00 +00:00
|
|
|
virtual BridgeHelperPtr createBridgeHelper(Context & context,
|
2018-10-03 10:44:43 +00:00
|
|
|
const Poco::Timespan & http_timeout_,
|
|
|
|
const std::string & connection_string_) const = 0;
|
2020-01-24 16:20:36 +00:00
|
|
|
|
|
|
|
virtual AccessType getRequiredAccessType() const = 0;
|
2018-09-25 00:21:20 +00:00
|
|
|
};
|
2018-09-25 14:29:44 +00:00
|
|
|
|
|
|
|
class TableFunctionJDBC : public ITableFunctionXDBC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "jdbc";
|
|
|
|
std::string getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
private:
|
2018-11-22 15:59:00 +00:00
|
|
|
BridgeHelperPtr createBridgeHelper(Context & context,
|
2018-10-03 10:44:43 +00:00
|
|
|
const Poco::Timespan & http_timeout_,
|
|
|
|
const std::string & connection_string_) const override
|
|
|
|
{
|
2018-11-22 15:59:00 +00:00
|
|
|
return std::make_shared<XDBCBridgeHelper<JDBCBridgeMixin>>(context, http_timeout_, connection_string_);
|
2018-09-25 14:29:44 +00:00
|
|
|
}
|
2020-01-24 16:20:36 +00:00
|
|
|
|
|
|
|
AccessType getRequiredAccessType() const override { return AccessType::jdbc; }
|
2018-09-25 14:29:44 +00:00
|
|
|
};
|
|
|
|
|
2018-09-28 02:46:33 +00:00
|
|
|
class TableFunctionODBC : public ITableFunctionXDBC
|
2018-09-25 14:29:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-09-28 02:46:33 +00:00
|
|
|
static constexpr auto name = "odbc";
|
2018-09-25 14:29:44 +00:00
|
|
|
std::string getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
private:
|
2018-11-22 15:59:00 +00:00
|
|
|
BridgeHelperPtr createBridgeHelper(Context & context,
|
2018-10-03 10:44:43 +00:00
|
|
|
const Poco::Timespan & http_timeout_,
|
|
|
|
const std::string & connection_string_) const override
|
|
|
|
{
|
2018-11-22 15:59:00 +00:00
|
|
|
return std::make_shared<XDBCBridgeHelper<ODBCBridgeMixin>>(context, http_timeout_, connection_string_);
|
2018-09-25 14:29:44 +00:00
|
|
|
}
|
2020-01-24 16:20:36 +00:00
|
|
|
|
|
|
|
AccessType getRequiredAccessType() const override { return AccessType::odbc; }
|
2018-09-25 14:29:44 +00:00
|
|
|
};
|
2018-09-25 00:21:20 +00:00
|
|
|
}
|