2018-08-20 02:34:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Client/Connection.h>
|
2021-02-19 12:51:26 +00:00
|
|
|
#include <Core/Block.h>
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2018-08-20 02:34:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
2021-02-19 12:51:26 +00:00
|
|
|
#include <Server/HTTP/HTMLForm.h>
|
|
|
|
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-08-20 02:34:00 +00:00
|
|
|
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
namespace Poco::Net
|
2018-08-20 02:34:00 +00:00
|
|
|
{
|
2021-04-10 23:33:54 +00:00
|
|
|
class NameValueCollection;
|
|
|
|
class MessageHeader;
|
2018-08-20 02:34:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
namespace boost::program_options
|
2018-08-20 02:34:00 +00:00
|
|
|
{
|
2021-04-10 23:33:54 +00:00
|
|
|
class variables_map;
|
2018-08-20 02:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// The base class containing the basic information about external table and
|
|
|
|
/// basic functions for extracting this information from text fields.
|
|
|
|
class BaseExternalTable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string file; /// File with data or '-' if stdin
|
|
|
|
std::string name; /// The name of the table
|
|
|
|
std::string format; /// Name of the data storage format
|
|
|
|
|
|
|
|
/// Description of the table structure: (column name, data type name)
|
|
|
|
std::vector<std::pair<std::string, std::string>> structure;
|
|
|
|
|
|
|
|
std::unique_ptr<ReadBuffer> read_buffer;
|
|
|
|
Block sample_block;
|
|
|
|
|
2021-02-19 12:51:26 +00:00
|
|
|
virtual ~BaseExternalTable() = default;
|
2018-08-20 02:34:00 +00:00
|
|
|
|
|
|
|
/// Initialize read_buffer, depending on the data source. By default, does nothing.
|
|
|
|
virtual void initReadBuffer() {}
|
|
|
|
|
|
|
|
/// Get the table data - a pair (a stream with the contents of the table, the name of the table)
|
2021-04-10 23:33:54 +00:00
|
|
|
ExternalTableDataPtr getData(ContextPtr context);
|
2018-08-20 02:34:00 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Clear all accumulated information
|
2021-02-07 20:37:55 +00:00
|
|
|
void clear();
|
2018-08-20 02:34:00 +00:00
|
|
|
|
|
|
|
/// Construct the `structure` vector from the text field `structure`
|
|
|
|
virtual void parseStructureFromStructureField(const std::string & argument);
|
|
|
|
|
|
|
|
/// Construct the `structure` vector from the text field `types`
|
|
|
|
virtual void parseStructureFromTypesField(const std::string & argument);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Initialize sample_block according to the structure of the table stored in the `structure`
|
|
|
|
void initSampleBlock();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Parsing of external table used in the tcp client.
|
|
|
|
class ExternalTable : public BaseExternalTable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void initReadBuffer() override;
|
|
|
|
|
|
|
|
/// Extract parameters from variables_map, which is built on the client command line
|
2021-02-19 12:51:26 +00:00
|
|
|
explicit ExternalTable(const boost::program_options::variables_map & external_options);
|
2018-08-20 02:34:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Parsing of external table used when sending tables via http
|
|
|
|
/// The `handlePart` function will be called for each table passed,
|
|
|
|
/// so it's also necessary to call `clean` at the end of the `handlePart`.
|
2021-04-10 23:33:54 +00:00
|
|
|
class ExternalTablesHandler : public HTMLForm::PartHandler, BaseExternalTable, WithContext
|
2018-08-20 02:34:00 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-04-10 23:33:54 +00:00
|
|
|
ExternalTablesHandler(ContextPtr context_, const Poco::Net::NameValueCollection & params_) : WithContext(context_), params(params_) {}
|
2018-08-20 02:34:00 +00:00
|
|
|
|
2021-02-19 12:51:26 +00:00
|
|
|
void handlePart(const Poco::Net::MessageHeader & header, ReadBuffer & stream) override;
|
2018-08-20 02:34:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const Poco::Net::NameValueCollection & params;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|