ClickHouse/src/Bridge/LibraryBridgeHelper.h

87 lines
2.6 KiB
C++
Raw Normal View History

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-03-07 13:55:40 +00:00
static constexpr inline size_t DEFAULT_PORT = 9012;
2021-03-05 09:38:00 +00:00
2021-06-01 12:20:52 +00:00
LibraryBridgeHelper(ContextPtr context_, const Block & sample_block, const Field & dictionary_id_);
2021-03-05 09:38:00 +00:00
bool initLibrary(const std::string & library_path, std::string library_settings, std::string attributes_names);
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
BlockInputStreamPtr loadIds(std::string ids_string);
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-03-24 08:41:42 +00:00
bool executeRequest(const Poco::URI & uri, ReadWriteBufferFromHTTP::OutStreamCallback out_stream_callback = {});
2021-03-05 10:43:47 +00:00
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;
String serviceAlias() const override { return "clickhouse-library-bridge"; }
2021-03-07 11:06:52 +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; }
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;
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
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-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-03-05 09:38:00 +00:00
}