2016-10-25 13:49:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-06-24 19:03:28 +00:00
|
|
|
#include <filesystem>
|
2016-10-25 12:14:27 +00:00
|
|
|
#include <memory>
|
2020-06-24 19:03:28 +00:00
|
|
|
#include <optional>
|
2021-04-17 12:37:48 +00:00
|
|
|
#include <Core/Settings.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2021-04-17 12:37:48 +00:00
|
|
|
#include <loggers/Loggers.h>
|
|
|
|
#include <Poco/Util/Application.h>
|
2021-05-13 22:56:42 +00:00
|
|
|
#include <Common/ProgressIndication.h>
|
2021-07-11 11:36:27 +00:00
|
|
|
#include <Client/IClient.h>
|
2018-04-20 15:32:40 +00:00
|
|
|
|
2016-10-25 12:14:27 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Lightweight Application for clickhouse-local
|
|
|
|
/// No networking, no extra configs and working directories, no pid and status files, no dictionaries, no logging.
|
|
|
|
/// Quiet mode by default
|
2021-07-11 11:36:27 +00:00
|
|
|
class LocalServer : public IClient
|
2016-10-25 12:14:27 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
LocalServer();
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void initialize(Poco::Util::Application & self) override;
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2018-08-26 01:31:12 +00:00
|
|
|
~LocalServer() override;
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2016-10-28 17:38:32 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
/** Composes CREATE subquery based on passed arguments (--structure --file --table and --input-format)
|
|
|
|
* This query will be executed first, before queries passed through --query argument
|
|
|
|
* Returns empty string if it cannot compose that query.
|
|
|
|
*/
|
|
|
|
std::string getInitialCreateTableQuery();
|
2016-10-28 17:38:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void tryInitPath();
|
2021-07-11 20:35:29 +00:00
|
|
|
|
2021-05-31 14:49:02 +00:00
|
|
|
void applyCmdOptions(ContextMutablePtr context);
|
2021-07-11 20:35:29 +00:00
|
|
|
|
2021-05-31 14:49:02 +00:00
|
|
|
void applyCmdSettings(ContextMutablePtr context);
|
2021-07-11 20:35:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void processQueries();
|
2021-07-11 20:35:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void setupUsers();
|
2021-07-11 20:35:29 +00:00
|
|
|
|
2020-06-24 19:03:28 +00:00
|
|
|
void cleanup();
|
2018-04-20 19:31:19 +00:00
|
|
|
|
2021-02-07 17:32:45 +00:00
|
|
|
|
2016-10-28 17:38:32 +00:00
|
|
|
protected:
|
2021-07-11 20:35:29 +00:00
|
|
|
void processMainImplException(const Exception & e) override;
|
|
|
|
|
|
|
|
int childMainImpl() override;
|
|
|
|
|
|
|
|
bool isInteractive() override;
|
|
|
|
|
|
|
|
bool processQueryFromInteractive(const String & input) override
|
|
|
|
{
|
2021-07-12 14:01:46 +00:00
|
|
|
return processQueryText(input);
|
2021-07-11 23:17:14 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 14:01:46 +00:00
|
|
|
void executeParsedQueryImpl() override;
|
2021-07-12 09:30:16 +00:00
|
|
|
|
2021-07-11 23:17:14 +00:00
|
|
|
void reportQueryError() const override;
|
|
|
|
|
2021-07-11 11:36:27 +00:00
|
|
|
void printHelpMessage(const OptionsDescription & options_description) override;
|
|
|
|
|
|
|
|
void readArguments(int argc, char ** argv, Arguments & common_arguments, std::vector<Arguments> &) override;
|
|
|
|
|
|
|
|
void addOptions(OptionsDescription & options_description) override;
|
|
|
|
|
|
|
|
void processOptions(const OptionsDescription & options_description,
|
|
|
|
const CommandLineOptions & options,
|
|
|
|
const std::vector<Arguments> &) override;
|
|
|
|
|
2021-07-12 09:30:16 +00:00
|
|
|
bool supportPasswordOption() const override { return false; }
|
2021-07-11 20:35:29 +00:00
|
|
|
|
|
|
|
std::optional<std::filesystem::path> temporary_directory_to_delete;
|
2021-05-13 22:56:42 +00:00
|
|
|
|
2021-07-11 20:35:29 +00:00
|
|
|
private:
|
|
|
|
ContextMutablePtr query_context;
|
2021-02-07 17:32:45 +00:00
|
|
|
|
2021-07-12 12:25:17 +00:00
|
|
|
std::exception_ptr exception;
|
|
|
|
|
2021-07-11 20:35:29 +00:00
|
|
|
void processQuery(const String & query, std::exception_ptr exception);
|
2016-10-25 12:14:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|