Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes in ODBC Bridge build #2879

Merged
merged 3 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbms/programs/odbc-bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ add_library (clickhouse-odbc-bridge-lib
Handlers.cpp
HandlerFactory.cpp
ODBCBridge.cpp
)
)

target_link_libraries (clickhouse-odbc-bridge-lib clickhouse_common_io daemon)
target_link_libraries (clickhouse-odbc-bridge-lib clickhouse_common_io daemon dbms)
target_include_directories (clickhouse-odbc-bridge-lib PUBLIC ${ClickHouse_SOURCE_DIR}/libs/libdaemon/include)

if (CLICKHOUSE_SPLIT_BINARY)
Expand Down
13 changes: 5 additions & 8 deletions dbms/src/Common/ODBCBridgeHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ namespace ErrorCodes
{
extern const int EXTERNAL_SERVER_IS_NOT_RESPONDING;
}
ODBCBridgeHelper::ODBCBridgeHelper(const Context & context_global_, const std::string & connection_string_)
: context_global(context_global_), connection_string(validateODBCConnectionString(connection_string_))
ODBCBridgeHelper::ODBCBridgeHelper(const Configuration & config_, const Poco::Timespan & http_timeout_, const std::string & connection_string_)
: config(config_), http_timeout(http_timeout_), connection_string(validateODBCConnectionString(connection_string_))
{
const auto & config = context_global.getConfigRef();
size_t bridge_port = config.getUInt("odbc_bridge.port", DEFAULT_PORT);
std::string bridge_host = config.getString("odbc_bridge.host", DEFAULT_HOST);

Expand All @@ -32,8 +31,6 @@ ODBCBridgeHelper::ODBCBridgeHelper(const Context & context_global_, const std::s
}
void ODBCBridgeHelper::startODBCBridge() const
{
const auto & config = context_global.getConfigRef();
const auto & settings = context_global.getSettingsRef();
Poco::Path path{config.getString("application.dir", "")};
path.setFileName("clickhouse-odbc-bridge");

Expand All @@ -44,7 +41,7 @@ void ODBCBridgeHelper::startODBCBridge() const
command << path.toString() << ' ';
command << "--http-port " << config.getUInt("odbc_bridge.port", DEFAULT_PORT) << ' ';
command << "--listen-host " << config.getString("odbc_bridge.listen_host", DEFAULT_HOST) << ' ';
command << "--http-timeout " << settings.http_receive_timeout.value.totalSeconds() << ' ';
command << "--http-timeout " << http_timeout.totalMicroseconds() << ' ';
if (config.has("logger.odbc_bridge_log"))
command << "--log-path " << config.getString("logger.odbc_bridge_log") << ' ';
if (config.has("logger.odbc_bridge_errlog"))
Expand All @@ -60,12 +57,12 @@ void ODBCBridgeHelper::startODBCBridge() const
cmd->wait();
}

std::vector<std::pair<std::string, std::string>> ODBCBridgeHelper::getURLParams(const NamesAndTypesList & cols, size_t max_block_size) const
std::vector<std::pair<std::string, std::string>> ODBCBridgeHelper::getURLParams(const std::string & cols, size_t max_block_size) const
{
std::vector<std::pair<std::string, std::string>> result;

result.emplace_back("connection_string", connection_string); /// already validated
result.emplace_back("columns", cols.toString());
result.emplace_back("columns", cols);
result.emplace_back("max_block_size", std::to_string(max_block_size));

return result;
Expand Down
11 changes: 8 additions & 3 deletions dbms/src/Common/ODBCBridgeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Interpreters/Context.h>
#include <Poco/Logger.h>
#include <Poco/URI.h>
#include <Poco/Util/AbstractConfiguration.h>

namespace DB
{
Expand All @@ -15,7 +16,11 @@ namespace ErrorCodes
class ODBCBridgeHelper
{
private:
const Context & context_global;

using Configuration = Poco::Util::AbstractConfiguration;

const Configuration & config;
Poco::Timespan http_timeout;

std::string connection_string;

Expand All @@ -32,9 +37,9 @@ class ODBCBridgeHelper
static constexpr inline auto MAIN_HANDLER = "/";
static constexpr inline auto PING_OK_ANSWER = "Ok.";

ODBCBridgeHelper(const Context & context_global_, const std::string & connection_string_);
ODBCBridgeHelper(const Configuration & config_, const Poco::Timespan & http_timeout_, const std::string & connection_string_);

std::vector<std::pair<std::string, std::string>> getURLParams(const NamesAndTypesList & cols, size_t max_block_size) const;
std::vector<std::pair<std::string, std::string>> getURLParams(const std::string & cols, size_t max_block_size) const;
bool checkODBCBridgeIsRunning() const;

void startODBCBridge() const;
Expand Down
5 changes: 2 additions & 3 deletions dbms/src/Dictionaries/ODBCDictionarySource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ namespace
std::unique_ptr<ReadWriteBufferFromHTTP> read_buf;
BlockInputStreamPtr reader;
};

}

static const size_t max_block_size = 8192;
Expand All @@ -72,7 +71,7 @@ ODBCDictionarySource::ODBCDictionarySource(const DictionaryStructure & dict_stru
query_builder{dict_struct, db, table, where, IdentifierQuotingStyle::None}, /// NOTE Better to obtain quoting style via ODBC interface.
load_all_query{query_builder.composeLoadAllQuery()},
invalidate_query{config.getString(config_prefix + ".invalidate_query", "")},
odbc_bridge_helper{context, config.getString(config_prefix + ".connection_string")},
odbc_bridge_helper{config, context.getSettingsRef().http_receive_timeout.value, config.getString(config_prefix + ".connection_string")},
timeouts{ConnectionTimeouts::getHTTPTimeouts(context.getSettingsRef())},
global_context(context)
{
Expand All @@ -84,7 +83,7 @@ ODBCDictionarySource::ODBCDictionarySource(const DictionaryStructure & dict_stru
bridge_url.setPort(bridge_port);
bridge_url.setScheme("http");

auto url_params = odbc_bridge_helper.getURLParams(sample_block.getNamesAndTypesList(), max_block_size);
auto url_params = odbc_bridge_helper.getURLParams(sample_block.getNamesAndTypesList().toString(), max_block_size);
for (const auto & [name, value] : url_params)
bridge_url.addQueryParameter(name, value);
}
Expand Down
2 changes: 0 additions & 2 deletions dbms/src/Dictionaries/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
add_executable (validate-odbc-connection-string validate-odbc-connection-string.cpp)
target_link_libraries (validate-odbc-connection-string dbms)
4 changes: 2 additions & 2 deletions dbms/src/Storages/StorageODBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ StorageODBC::StorageODBC(const std::string & table_name_,
const ColumnsDescription & columns_,
const Context & context_)
: IStorageURLBase(Poco::URI(), context_, table_name_, ODBCBridgeHelper::DEFAULT_FORMAT, columns_)
, odbc_bridge_helper(context_, connection_string)
, odbc_bridge_helper(context_global.getConfigRef(), context_global.getSettingsRef().http_receive_timeout.value, connection_string)
, remote_database_name(remote_database_name_)
, remote_table_name(remote_table_name_)
, log(&Poco::Logger::get("StorageODBC"))
Expand Down Expand Up @@ -64,7 +64,7 @@ std::vector<std::pair<std::string, std::string>> StorageODBC::getReadURIParams(c
auto column_data = getColumn(name);
cols.emplace_back(column_data.name, column_data.type);
}
return odbc_bridge_helper.getURLParams(cols, max_block_size);
return odbc_bridge_helper.getURLParams(cols.toString(), max_block_size);
}

std::function<void(std::ostream &)> StorageODBC::getReadPOSTDataCallback(const Names & /*column_names*/,
Expand Down