LocalServer.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <Client/ClientBase.h>
  3. #include <Client/LocalConnection.h>
  4. #include <Common/StatusFile.h>
  5. #include <Common/InterruptListener.h>
  6. #include <Loggers/Loggers.h>
  7. #include <Core/Settings.h>
  8. #include <Interpreters/Context.h>
  9. #include <filesystem>
  10. #include <memory>
  11. #include <optional>
  12. namespace DB
  13. {
  14. /// Lightweight Application for clickhouse-local
  15. /// No networking, no extra configs and working directories, no pid and status files, no dictionaries, no logging.
  16. /// Quiet mode by default
  17. class LocalServer : public ClientBase, public Loggers
  18. {
  19. public:
  20. LocalServer() = default;
  21. void initialize(Poco::Util::Application & self) override;
  22. int main(const std::vector<String> & /*args*/) override;
  23. protected:
  24. void connect() override;
  25. void processError(const String & query) const override;
  26. String getName() const override { return "local"; }
  27. void printHelpMessage(const OptionsDescription & options_description) override;
  28. void addOptions(OptionsDescription & options_description) override;
  29. void processOptions(const OptionsDescription & options_description, const CommandLineOptions & options,
  30. const std::vector<Arguments> &, const std::vector<Arguments> &) override;
  31. void processConfig() override;
  32. void readArguments(int argc, char ** argv, Arguments & common_arguments, std::vector<Arguments> &, std::vector<Arguments> &) override;
  33. void updateLoggerLevel(const String & logs_level) override;
  34. private:
  35. /** Composes CREATE subquery based on passed arguments (--structure --file --table and --input-format)
  36. * This query will be executed first, before queries passed through --query argument
  37. * Returns empty string if it cannot compose that query.
  38. */
  39. std::string getInitialCreateTableQuery();
  40. void tryInitPath();
  41. void setupUsers();
  42. void cleanup();
  43. void applyCmdOptions(ContextMutablePtr context);
  44. void applyCmdSettings(ContextMutablePtr context);
  45. std::optional<StatusFile> status;
  46. std::optional<std::filesystem::path> temporary_directory_to_delete;
  47. };
  48. }