2016-10-25 13:49:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-07-15 16:36:45 +00:00
|
|
|
#include <Client/ClientApplicationBase.h>
|
2021-08-17 19:59:51 +00:00
|
|
|
#include <Client/LocalConnection.h>
|
2021-07-23 20:54:49 +00:00
|
|
|
|
2024-07-10 16:10:19 +00:00
|
|
|
#include <Core/ServerSettings.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2024-07-10 16:10:19 +00:00
|
|
|
#include <Loggers/Loggers.h>
|
|
|
|
#include <Common/InterruptListener.h>
|
|
|
|
#include <Common/StatusFile.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
|
2024-07-15 16:36:45 +00:00
|
|
|
class LocalServer : public ClientApplicationBase, public Loggers
|
2016-10-25 12:14:27 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-07-23 20:56:47 +00:00
|
|
|
LocalServer() = default;
|
2021-09-11 11:34:22 +00:00
|
|
|
|
2021-07-23 20:56:47 +00:00
|
|
|
void initialize(Poco::Util::Application & self) override;
|
2021-09-11 11:34:22 +00:00
|
|
|
|
2021-09-04 18:19:01 +00:00
|
|
|
int main(const std::vector<String> & /*args*/) override;
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2021-07-23 20:56:47 +00:00
|
|
|
protected:
|
2024-06-25 14:23:37 +00:00
|
|
|
Poco::Util::LayeredConfiguration & getClientConfiguration() override;
|
|
|
|
|
2021-09-04 18:19:01 +00:00
|
|
|
void connect() override;
|
2022-03-14 11:00:47 +00:00
|
|
|
|
2021-08-19 11:07:47 +00:00
|
|
|
void processError(const String & query) const override;
|
2022-03-14 11:00:47 +00:00
|
|
|
|
2021-09-19 21:42:28 +00:00
|
|
|
String getName() const override { return "local"; }
|
2021-08-23 08:50:12 +00:00
|
|
|
|
2024-04-26 11:19:22 +00:00
|
|
|
void printHelpMessage(const OptionsDescription & options_description, bool verbose) override;
|
2021-07-28 12:56:11 +00:00
|
|
|
|
2021-10-14 13:34:05 +00:00
|
|
|
void addOptions(OptionsDescription & options_description) override;
|
2022-03-14 11:00:47 +00:00
|
|
|
|
2021-08-23 08:50:12 +00:00
|
|
|
void processOptions(const OptionsDescription & options_description, const CommandLineOptions & options,
|
2022-02-10 09:43:08 +00:00
|
|
|
const std::vector<Arguments> &, const std::vector<Arguments> &) override;
|
2022-03-14 11:00:47 +00:00
|
|
|
|
2021-07-29 12:48:07 +00:00
|
|
|
void processConfig() override;
|
2022-03-01 09:22:12 +00:00
|
|
|
void readArguments(int argc, char ** argv, Arguments & common_arguments, std::vector<Arguments> &, std::vector<Arguments> &) override;
|
|
|
|
|
2022-04-05 13:38:44 +00:00
|
|
|
void updateLoggerLevel(const String & logs_level) override;
|
2022-04-05 12:46:18 +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
|
|
|
|
2024-07-25 14:36:32 +00:00
|
|
|
void createClientContext();
|
|
|
|
|
2024-06-26 00:29:04 +00:00
|
|
|
ServerSettings server_settings;
|
|
|
|
|
2021-07-23 20:54:49 +00:00
|
|
|
std::optional<StatusFile> status;
|
2021-07-18 14:42:41 +00:00
|
|
|
std::optional<std::filesystem::path> temporary_directory_to_delete;
|
2024-03-25 15:39:33 +00:00
|
|
|
|
|
|
|
std::unique_ptr<ReadBufferFromFile> input;
|
2016-10-25 12:14:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|