2016-10-25 13:49:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-07-29 12:48:07 +00:00
|
|
|
#include <Client/ClientBase.h>
|
2021-08-17 19:59:51 +00:00
|
|
|
#include <Client/LocalConnection.h>
|
2021-07-23 20:54:49 +00:00
|
|
|
|
|
|
|
#include <Common/ProgressIndication.h>
|
|
|
|
#include <Common/StatusFile.h>
|
2021-08-01 22:12:15 +00:00
|
|
|
#include <Common/InterruptListener.h>
|
2021-07-29 12:48:07 +00:00
|
|
|
#include <loggers/Loggers.h>
|
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-07-29 12:48:07 +00:00
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
2021-07-23 20:54:49 +00:00
|
|
|
|
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-22 21:27:26 +00:00
|
|
|
class LocalServer : public ClientBase, public Loggers
|
2016-10-25 12:14:27 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-07-23 20:56:47 +00:00
|
|
|
LocalServer() = default;
|
|
|
|
|
|
|
|
void initialize(Poco::Util::Application & self) override;
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2021-07-23 20:56:47 +00:00
|
|
|
protected:
|
2021-08-21 10:55:54 +00:00
|
|
|
void processSingleQuery(const String & query_to_execute, ASTPtr parsed_query) override;
|
|
|
|
bool processMultiQuery(const String & all_queries_text) override;
|
|
|
|
|
2021-08-19 11:07:47 +00:00
|
|
|
void processError(const String & query) const override;
|
2021-08-01 20:28:39 +00:00
|
|
|
void loadSuggestionData(Suggest &) override;
|
2021-08-19 11:07:47 +00:00
|
|
|
String getQueryTextPrefix() override;
|
2021-07-29 12:48:07 +00:00
|
|
|
void printHelpMessage(const OptionsDescription & options_description) override;
|
2021-07-28 12:56:11 +00:00
|
|
|
|
2021-08-19 11:07:47 +00:00
|
|
|
void readArguments(int argc, char ** argv, Arguments & common_arguments, std::vector<Arguments> &) override;
|
2021-07-29 12:48:07 +00:00
|
|
|
void addAndCheckOptions(OptionsDescription & options_description, po::variables_map & options, Arguments & arguments) override;
|
|
|
|
void processOptions(const OptionsDescription & options_description,
|
|
|
|
const CommandLineOptions & options,
|
|
|
|
const std::vector<Arguments> &) override;
|
|
|
|
void processConfig() override;
|
2021-07-11 23:17:14 +00:00
|
|
|
|
2021-07-29 12:48:07 +00:00
|
|
|
int mainImpl() override;
|
2021-07-11 11:36:27 +00:00
|
|
|
|
2021-07-11 20:35:29 +00:00
|
|
|
private:
|
2021-07-23 20:56:47 +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();
|
|
|
|
|
|
|
|
void tryInitPath();
|
|
|
|
void setupUsers();
|
|
|
|
void cleanup();
|
|
|
|
|
2021-08-19 11:07:47 +00:00
|
|
|
void applyCmdOptions(ContextMutablePtr context);
|
|
|
|
void applyCmdSettings(ContextMutablePtr context);
|
2021-02-07 17:32:45 +00:00
|
|
|
|
2021-07-23 20:54:49 +00:00
|
|
|
std::optional<StatusFile> status;
|
|
|
|
|
2021-07-11 20:35:29 +00:00
|
|
|
void processQuery(const String & query, std::exception_ptr exception);
|
2021-07-18 14:42:41 +00:00
|
|
|
|
|
|
|
std::optional<std::filesystem::path> temporary_directory_to_delete;
|
2021-08-01 22:12:15 +00:00
|
|
|
|
2021-08-02 14:46:21 +00:00
|
|
|
/// Used to cancel query on ctrl-c. Lives for single query execution.
|
2021-08-01 22:12:15 +00:00
|
|
|
std::optional<InterruptListener> interrupt_listener;
|
|
|
|
|
|
|
|
std::mutex interrupt_listener_mutex;
|
|
|
|
|
2021-08-02 14:46:21 +00:00
|
|
|
/// Was currently executed query cancelled by ctrl-c in interactive mode?
|
2021-08-01 22:12:15 +00:00
|
|
|
bool cancelled = true;
|
2016-10-25 12:14:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|