2018-06-11 12:13:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <Poco/URI.h>
|
|
|
|
#include <ext/shared_ptr_helper.h>
|
|
|
|
|
2019-08-24 21:20:20 +00:00
|
|
|
|
2018-06-11 12:13:00 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This class represents table engine for external urls.
|
|
|
|
* It sends HTTP GET to server when select is called and
|
|
|
|
* HTTP POST when insert is called. In POST request the data is send
|
|
|
|
* using Chunked transfer encoding, so server have to support it.
|
|
|
|
*/
|
2018-08-09 18:49:05 +00:00
|
|
|
class IStorageURLBase : public IStorage
|
2018-06-11 12:13:00 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-02-19 16:07:28 +00:00
|
|
|
Pipes read(
|
2019-08-24 21:20:20 +00:00
|
|
|
const Names & column_names,
|
2018-06-11 12:13:00 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
2018-06-25 12:21:54 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2018-06-11 12:13:00 +00:00
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2019-02-27 18:26:24 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
|
2018-06-11 12:13:00 +00:00
|
|
|
|
|
|
|
protected:
|
2019-08-24 21:20:20 +00:00
|
|
|
IStorageURLBase(
|
|
|
|
const Poco::URI & uri_,
|
2018-08-09 18:49:05 +00:00
|
|
|
const Context & context_,
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & id_,
|
2018-06-11 12:13:00 +00:00
|
|
|
const String & format_name_,
|
2019-08-24 21:20:20 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2019-11-19 12:46:07 +00:00
|
|
|
const ConstraintsDescription & constraints_,
|
|
|
|
const String & compression_method_);
|
2018-06-11 12:13:00 +00:00
|
|
|
|
|
|
|
Poco::URI uri;
|
2018-08-09 18:49:05 +00:00
|
|
|
const Context & context_global;
|
2019-11-19 12:46:07 +00:00
|
|
|
String compression_method;
|
2018-08-09 18:49:05 +00:00
|
|
|
|
|
|
|
private:
|
2018-06-11 12:13:00 +00:00
|
|
|
String format_name;
|
|
|
|
|
2018-08-09 18:49:05 +00:00
|
|
|
virtual std::string getReadMethod() const;
|
|
|
|
|
2019-08-24 21:20:20 +00:00
|
|
|
virtual std::vector<std::pair<std::string, std::string>> getReadURIParams(
|
|
|
|
const Names & column_names,
|
2018-08-09 18:49:05 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
2019-02-19 00:48:52 +00:00
|
|
|
size_t max_block_size) const;
|
2018-08-09 18:49:05 +00:00
|
|
|
|
2019-08-24 21:20:20 +00:00
|
|
|
virtual std::function<void(std::ostream &)> getReadPOSTDataCallback(
|
|
|
|
const Names & column_names,
|
2018-08-09 18:49:05 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
2019-02-19 00:48:52 +00:00
|
|
|
size_t max_block_size) const;
|
2018-09-22 14:58:03 +00:00
|
|
|
|
|
|
|
virtual Block getHeaderBlock(const Names & column_names) const = 0;
|
2018-08-09 18:49:05 +00:00
|
|
|
};
|
|
|
|
|
2019-08-24 21:20:20 +00:00
|
|
|
|
2018-08-09 18:49:05 +00:00
|
|
|
class StorageURL : public ext::shared_ptr_helper<StorageURL>, public IStorageURLBase
|
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageURL>;
|
2018-08-09 18:49:05 +00:00
|
|
|
public:
|
2019-08-24 21:20:20 +00:00
|
|
|
StorageURL(
|
|
|
|
const Poco::URI & uri_,
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id_,
|
2018-08-09 18:49:05 +00:00
|
|
|
const String & format_name_,
|
|
|
|
const ColumnsDescription & columns_,
|
2019-08-24 21:20:20 +00:00
|
|
|
const ConstraintsDescription & constraints_,
|
2019-11-19 12:46:07 +00:00
|
|
|
Context & context_,
|
|
|
|
const String & compression_method_)
|
2019-12-04 16:06:55 +00:00
|
|
|
: IStorageURLBase(uri_, context_, table_id_, format_name_, columns_, constraints_, compression_method_)
|
2018-08-09 18:49:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
{
|
|
|
|
return "URL";
|
|
|
|
}
|
2018-09-22 14:58:03 +00:00
|
|
|
|
|
|
|
Block getHeaderBlock(const Names & /*column_names*/) const override
|
|
|
|
{
|
|
|
|
return getSampleBlock();
|
|
|
|
}
|
2018-06-11 12:13:00 +00:00
|
|
|
};
|
|
|
|
}
|