2021-03-05 09:38:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Poco/Logger.h>
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/URI.h>
|
2021-03-07 11:06:52 +00:00
|
|
|
#include <Common/Bridge/IBridgeHelper.h>
|
2021-03-05 09:38:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
class LibraryBridgeHelper : public IBridgeHelper
|
2021-03-05 09:38:00 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2021-03-07 13:55:40 +00:00
|
|
|
static constexpr inline size_t DEFAULT_PORT = 9012;
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
LibraryBridgeHelper(const Context & context_, const std::string & dictionary_id_);
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-10 08:09:05 +00:00
|
|
|
bool initLibrary(const std::string & library_path, const std::string library_settings);
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-05 15:37:43 +00:00
|
|
|
bool cloneLibrary(const std::string & other_dictionary_id);
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
bool removeLibrary();
|
|
|
|
|
2021-03-05 09:38:00 +00:00
|
|
|
BlockInputStreamPtr loadAll(const std::string attributes_string, const Block & sample_block);
|
|
|
|
|
|
|
|
BlockInputStreamPtr loadIds(const std::string attributes_string, const std::string ids_string, const Block & sample_block);
|
|
|
|
|
2021-03-06 18:44:40 +00:00
|
|
|
BlockInputStreamPtr loadKeys();
|
|
|
|
|
2021-03-05 10:43:47 +00:00
|
|
|
bool isModified();
|
|
|
|
|
|
|
|
bool supportsSelectiveLoad();
|
|
|
|
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
protected:
|
|
|
|
void startBridge(std::unique_ptr<ShellCommand> cmd) const override;
|
|
|
|
|
|
|
|
const String serviceAlias() const override { return "clickhouse-library-bridge"; }
|
|
|
|
|
|
|
|
const String serviceFileName() const override { return serviceAlias(); }
|
|
|
|
|
|
|
|
size_t getDefaultPort() const override { return DEFAULT_PORT; }
|
|
|
|
|
|
|
|
bool startBridgeManually() const override { return false; }
|
|
|
|
|
|
|
|
const String configPrefix() const override { return "library_bridge"; }
|
|
|
|
|
|
|
|
const Context & getContext() const override { return context; }
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & getConfig() const override { return config; }
|
|
|
|
|
|
|
|
Poco::Logger * getLog() const override { return log; }
|
|
|
|
|
|
|
|
const Poco::Timespan & getHTTPTimeout() const override { return http_timeout; }
|
|
|
|
|
|
|
|
Poco::URI createBaseURI() const override;
|
|
|
|
|
|
|
|
private:
|
2021-03-05 10:43:47 +00:00
|
|
|
static constexpr inline auto LIB_NEW_METHOD = "libNew";
|
2021-03-05 15:37:43 +00:00
|
|
|
static constexpr inline auto LIB_CLONE_METHOD = "libClone";
|
2021-03-05 10:43:47 +00:00
|
|
|
static constexpr inline auto LIB_DELETE_METHOD = "libDelete";
|
|
|
|
static constexpr inline auto LOAD_ALL_METHOD = "loadAll";
|
|
|
|
static constexpr inline auto LOAD_IDS_METHOD = "loadIds";
|
2021-03-06 18:44:40 +00:00
|
|
|
static constexpr inline auto LOAD_KEYS_METHOD = "loadKeys";
|
2021-03-05 10:43:47 +00:00
|
|
|
static constexpr inline auto IS_MODIFIED_METHOD = "isModified";
|
|
|
|
static constexpr inline auto SUPPORTS_SELECTIVE_LOAD_METHOD = "supportsSelectiveLoad";
|
2021-03-05 09:38:00 +00:00
|
|
|
|
|
|
|
Poco::URI getDictionaryURI() const;
|
|
|
|
|
|
|
|
Poco::Logger * log;
|
|
|
|
const Context & context;
|
2021-03-07 11:06:52 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config;
|
|
|
|
const Poco::Timespan http_timeout;
|
2021-03-05 09:38:00 +00:00
|
|
|
|
|
|
|
const std::string dictionary_id;
|
|
|
|
std::string bridge_host;
|
|
|
|
size_t bridge_port;
|
|
|
|
};
|
|
|
|
}
|