ClickHouse/src/TableFunctions/ITableFunctionXDBC.h

80 lines
2.3 KiB
C++
Raw Normal View History

2018-09-25 00:21:20 +00:00
#pragma once
#include <Storages/StorageXDBC.h>
2018-09-25 00:21:20 +00:00
#include <TableFunctions/ITableFunction.h>
#include <Poco/Util/AbstractConfiguration.h>
2021-03-12 21:12:34 +00:00
#include <Bridge/XDBCBridgeHelper.h>
#if !defined(ARCADIA_BUILD)
# include <Common/config.h>
#endif
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:
StoragePtr executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name, ColumnsDescription cached_columns) const override;
2018-09-25 00:21:20 +00:00
/* A factory method to create bridge helper, that will assist in remote interaction */
virtual BridgeHelperPtr createBridgeHelper(Context & context,
const Poco::Timespan & http_timeout_,
const std::string & connection_string_) const = 0;
ColumnsDescription getActualTableStructure(const Context & context) const override;
void parseArguments(const ASTPtr & ast_function, const Context & context) override;
2021-03-22 14:09:38 +00:00
void startBridgeIfNot(const Context & context) const;
String connection_string;
String schema_name;
String remote_table_name;
2021-03-22 14:09:38 +00:00
mutable BridgeHelperPtr helper;
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;
}
private:
BridgeHelperPtr createBridgeHelper(Context & context,
const Poco::Timespan & http_timeout_,
const std::string & connection_string_) const override
{
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
const char * getStorageTypeName() const override { return "JDBC"; }
2018-09-25 14:29:44 +00:00
};
class TableFunctionODBC : public ITableFunctionXDBC
2018-09-25 14:29:44 +00:00
{
public:
static constexpr auto name = "odbc";
2018-09-25 14:29:44 +00:00
std::string getName() const override
{
return name;
}
private:
BridgeHelperPtr createBridgeHelper(Context & context,
const Poco::Timespan & http_timeout_,
const std::string & connection_string_) const override
{
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
const char * getStorageTypeName() const override { return "ODBC"; }
2018-09-25 14:29:44 +00:00
};
2018-09-25 00:21:20 +00:00
}