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>
|
|
|
|
#include <Common/ProgressBar.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
|
2019-06-14 14:00:37 +00:00
|
|
|
class LocalServer : public Poco::Util::Application, public Loggers
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
int main(const std::vector<std::string> & args) override;
|
2016-10-25 12:14:27 +00:00
|
|
|
|
2018-04-20 19:31:19 +00:00
|
|
|
void init(int argc, char ** argv);
|
|
|
|
|
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-05-31 14:49:02 +00:00
|
|
|
void applyCmdOptions(ContextMutablePtr context);
|
|
|
|
void applyCmdSettings(ContextMutablePtr context);
|
2017-04-01 07:20:54 +00:00
|
|
|
void processQueries();
|
|
|
|
void setupUsers();
|
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:
|
2020-04-17 20:56:38 +00:00
|
|
|
SharedContextHolder shared_context;
|
2021-05-31 14:49:02 +00:00
|
|
|
ContextMutablePtr global_context;
|
2018-04-20 19:31:19 +00:00
|
|
|
|
|
|
|
/// Settings specified via command line args
|
|
|
|
Settings cmd_settings;
|
2021-04-15 20:39:39 +00:00
|
|
|
ProgressBar progress_bar;
|
2021-02-07 17:32:45 +00:00
|
|
|
Progress progress;
|
|
|
|
Stopwatch watch;
|
|
|
|
|
2020-06-24 19:03:28 +00:00
|
|
|
std::optional<std::filesystem::path> temporary_directory_to_delete;
|
2016-10-25 12:14:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|