2021-03-05 09:38:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/Context.h>
|
2021-03-10 18:02:43 +00:00
|
|
|
#include <IO/ReadWriteBufferFromHTTP.h>
|
2021-03-05 09:38:00 +00:00
|
|
|
#include <Poco/Logger.h>
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/URI.h>
|
2021-03-12 21:12:34 +00:00
|
|
|
#include <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-07-30 14:20:57 +00:00
|
|
|
struct LibraryInitData
|
|
|
|
{
|
|
|
|
String library_path;
|
|
|
|
String library_settings;
|
|
|
|
String dict_attributes;
|
|
|
|
};
|
|
|
|
|
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-07-30 14:20:57 +00:00
|
|
|
LibraryBridgeHelper(ContextPtr context_, const Block & sample_block, const Field & dictionary_id_, const LibraryInitData & library_data_);
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-07-30 14:20:57 +00:00
|
|
|
bool initLibrary(bool check_bridge = true) const;
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-22 14:39:17 +00:00
|
|
|
bool cloneLibrary(const Field & other_dictionary_id);
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
bool removeLibrary();
|
|
|
|
|
2021-03-10 18:02:43 +00:00
|
|
|
bool isModified();
|
|
|
|
|
|
|
|
bool supportsSelectiveLoad();
|
|
|
|
|
2021-03-24 09:23:29 +00:00
|
|
|
BlockInputStreamPtr loadAll();
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-07-30 14:20:57 +00:00
|
|
|
BlockInputStreamPtr loadIds(std::string ids_string, const std::vector<uint64_t> ids);
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-24 09:23:29 +00:00
|
|
|
BlockInputStreamPtr loadKeys(const Block & requested_block);
|
2021-03-06 18:44:40 +00:00
|
|
|
|
2021-03-24 08:41:42 +00:00
|
|
|
BlockInputStreamPtr loadBase(const Poco::URI & uri, ReadWriteBufferFromHTTP::OutStreamCallback out_stream_callback = {});
|
2021-03-05 10:43:47 +00:00
|
|
|
|
2021-07-30 14:20:57 +00:00
|
|
|
bool executeRequest(const Poco::URI & uri, ReadWriteBufferFromHTTP::OutStreamCallback out_stream_callback = {}) const;
|
|
|
|
|
|
|
|
LibraryInitData getLibraryData() const { return library_data; }
|
2021-03-05 10:43:47 +00:00
|
|
|
|
2021-07-30 14:20:57 +00:00
|
|
|
void setInitialized() { library_initialized = true; }
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
protected:
|
2021-07-30 14:20:57 +00:00
|
|
|
bool checkBridgeIsRunning() const override;
|
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
void startBridge(std::unique_ptr<ShellCommand> cmd) const override;
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
String serviceAlias() const override { return "clickhouse-library-bridge"; }
|
2021-03-07 11:06:52 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
String serviceFileName() const override { return serviceAlias(); }
|
2021-03-07 11:06:52 +00:00
|
|
|
|
|
|
|
size_t getDefaultPort() const override { return DEFAULT_PORT; }
|
|
|
|
|
|
|
|
bool startBridgeManually() const override { return false; }
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
String configPrefix() const override { return "library_bridge"; }
|
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; }
|
|
|
|
|
2021-04-29 16:11:20 +00:00
|
|
|
Poco::Timespan getHTTPTimeout() const override { return http_timeout; }
|
2021-03-07 11:06:52 +00:00
|
|
|
|
|
|
|
Poco::URI createBaseURI() const override;
|
|
|
|
|
2021-07-30 14:20:57 +00:00
|
|
|
ReadWriteBufferFromHTTP::OutStreamCallback getInitLibraryCallback() const;
|
|
|
|
|
2021-03-07 11:06:52 +00:00
|
|
|
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";
|
2021-07-30 14:20:57 +00:00
|
|
|
static constexpr inline auto PING = "ping";
|
2021-03-05 10:43:47 +00:00
|
|
|
static constexpr inline auto SUPPORTS_SELECTIVE_LOAD_METHOD = "supportsSelectiveLoad";
|
2021-03-05 09:38:00 +00:00
|
|
|
|
2021-03-24 09:23:29 +00:00
|
|
|
Poco::URI createRequestURI(const String & method) const;
|
2021-03-05 09:38:00 +00:00
|
|
|
|
|
|
|
Poco::Logger * log;
|
2021-03-24 08:41:42 +00:00
|
|
|
const Block sample_block;
|
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
|
|
|
|
2021-07-30 14:20:57 +00:00
|
|
|
LibraryInitData library_data;
|
2021-03-22 14:39:17 +00:00
|
|
|
Field dictionary_id;
|
2021-03-05 09:38:00 +00:00
|
|
|
std::string bridge_host;
|
|
|
|
size_t bridge_port;
|
2021-07-30 14:20:57 +00:00
|
|
|
bool library_initialized = false;
|
2021-03-05 09:38:00 +00:00
|
|
|
};
|
2021-04-10 23:33:54 +00:00
|
|
|
|
2021-03-05 09:38:00 +00:00
|
|
|
}
|