ClickHouse/programs/local/LocalServer.h

100 lines
2.7 KiB
C++
Raw Normal View History

#pragma once
#include <filesystem>
#include <memory>
#include <optional>
#include <Core/Settings.h>
#include <Interpreters/Context.h>
#include <loggers/Loggers.h>
#include <Poco/Util/Application.h>
#include <Common/ProgressIndication.h>
2021-07-11 11:36:27 +00:00
#include <Client/IClient.h>
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-14 21:46:40 +00:00
class LocalServer : public IClient, public Loggers
{
public:
LocalServer();
~LocalServer() override
{
if (global_context)
global_context->shutdown(); /// required for properly exception handling
}
private:
/** 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();
2021-05-31 14:49:02 +00:00
void applyCmdOptions(ContextMutablePtr context);
2021-05-31 14:49:02 +00:00
void applyCmdSettings(ContextMutablePtr context);
void processQueries();
void setupUsers();
void cleanup();
protected:
void processMainImplException(const Exception & e) override;
2021-07-14 21:46:40 +00:00
void initializeChild() 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; }
bool processFile(const String & file) override
{
auto text = getInitialCreateTableQuery();
String queries_from_file;
ReadBufferFromFile in(file);
readStringUntilEOF(queries_from_file, in);
text += queries_from_file;
return processMultiQuery(text);
}
private:
ContextMutablePtr query_context;
2021-02-07 17:32:45 +00:00
2021-07-12 12:25:17 +00:00
std::exception_ptr exception;
void processQuery(const String & query, std::exception_ptr exception);
std::optional<std::filesystem::path> temporary_directory_to_delete;
};
}