From db1bb630e04835b9b636c91305822ebe27d91613 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 19 Jan 2020 03:23:35 +0300 Subject: [PATCH] Fixed configuration of replxx --- dbms/programs/client/Client.cpp | 20 +------------------ dbms/programs/client/Suggest.h | 4 ++-- ...StorageSystemBuildOptions.generated.cpp.in | 1 + libs/libcommon/include/common/LineReader.h | 2 +- libs/libcommon/src/LineReader.cpp | 15 ++++++-------- 5 files changed, 11 insertions(+), 31 deletions(-) diff --git a/dbms/programs/client/Client.cpp b/dbms/programs/client/Client.cpp index 7f014dcea79..c73c87885b1 100644 --- a/dbms/programs/client/Client.cpp +++ b/dbms/programs/client/Client.cpp @@ -479,7 +479,7 @@ private: if (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false)) /// Load suggestion data from the server. - Suggest::instance()->load(connection_parameters, config().getInt("suggestion_limit")); + Suggest::instance().load(connection_parameters, config().getInt("suggestion_limit")); /// Load command history if present. if (config().has("history_file")) @@ -543,17 +543,6 @@ private: } else { - /// This is intended for testing purposes. - if (config().getBool("always_load_suggestion_data", false)) - { -#if USE_REPLXX - SCOPE_EXIT({ Suggest::instance().finalize(); }); - Suggest::instance().load(connection_parameters, config().getInt("suggestion_limit")); -#else - throw Exception("Command line suggestions cannot work without line editing library", ErrorCodes::BAD_ARGUMENTS); -#endif - } - query_id = config().getString("query_id", ""); nonInteractive(); @@ -1823,13 +1812,6 @@ public: server_logs_file = options["server_logs_file"].as(); if (options.count("disable_suggestion")) config().setBool("disable_suggestion", true); - if (options.count("always_load_suggestion_data")) - { - if (options.count("disable_suggestion")) - throw Exception("Command line parameters disable_suggestion (-A) and always_load_suggestion_data cannot be specified simultaneously", - ErrorCodes::BAD_ARGUMENTS); - config().setBool("always_load_suggestion_data", true); - } if (options.count("suggestion_limit")) config().setInt("suggestion_limit", options["suggestion_limit"].as()); diff --git a/dbms/programs/client/Suggest.h b/dbms/programs/client/Suggest.h index 2fea534a986..bd4f239ddc7 100644 --- a/dbms/programs/client/Suggest.h +++ b/dbms/programs/client/Suggest.h @@ -18,10 +18,10 @@ namespace ErrorCodes class Suggest : public LineReader::Suggest, boost::noncopyable { public: - static Suggest * instance() + static Suggest & instance() { static Suggest instance; - return &instance; + return instance; } void load(const ConnectionParameters & connection_parameters, size_t suggestion_limit); diff --git a/dbms/src/Storages/System/StorageSystemBuildOptions.generated.cpp.in b/dbms/src/Storages/System/StorageSystemBuildOptions.generated.cpp.in index 65c4f19b7cb..550ead28996 100644 --- a/dbms/src/Storages/System/StorageSystemBuildOptions.generated.cpp.in +++ b/dbms/src/Storages/System/StorageSystemBuildOptions.generated.cpp.in @@ -61,6 +61,7 @@ const char * auto_config_build[] "USE_HYPERSCAN", "@USE_HYPERSCAN@", "USE_SIMDJSON", "@USE_SIMDJSON@", "USE_POCO_REDIS", "@USE_POCO_REDIS@", + "USE_REPLXX", "@USE_REPLXX@", nullptr, nullptr }; diff --git a/libs/libcommon/include/common/LineReader.h b/libs/libcommon/include/common/LineReader.h index 120ff76dac6..3661c6ef316 100644 --- a/libs/libcommon/include/common/LineReader.h +++ b/libs/libcommon/include/common/LineReader.h @@ -22,7 +22,7 @@ public: WordsRange getCompletions(const String & prefix, size_t prefix_length) const; }; - LineReader(const Suggest * suggest, const String & history_file_path, char extender, char delimiter = 0); /// if delimiter != 0, then it's multiline mode + LineReader(const Suggest & suggest, const String & history_file_path, char extender, char delimiter = 0); /// if delimiter != 0, then it's multiline mode ~LineReader(); /// Reads the whole line until delimiter (in multiline mode) or until the last line without extender. diff --git a/libs/libcommon/src/LineReader.cpp b/libs/libcommon/src/LineReader.cpp index 17d69f91d15..bab03dedbe5 100644 --- a/libs/libcommon/src/LineReader.cpp +++ b/libs/libcommon/src/LineReader.cpp @@ -58,7 +58,7 @@ LineReader::Suggest::WordsRange LineReader::Suggest::getCompletions(const String }); } -LineReader::LineReader(const Suggest * suggest, const String & history_file_path_, char extender_, char delimiter_) +LineReader::LineReader(const Suggest & suggest, const String & history_file_path_, char extender_, char delimiter_) : history_file_path(history_file_path_), extender(extender_), delimiter(delimiter_) { #if USE_REPLXX @@ -68,18 +68,15 @@ LineReader::LineReader(const Suggest * suggest, const String & history_file_path if (!history_file_path.empty()) rx.history_load(history_file_path); - auto callback = [suggest] (const String & context, size_t context_size) + auto callback = [&suggest] (const String & context, size_t context_size) { - auto range = suggest->getCompletions(context, context_size); + auto range = suggest.getCompletions(context, context_size); return replxx::Replxx::completions_t(range.first, range.second); }; - if (suggest) - { - rx.set_completion_callback(callback); - rx.set_complete_on_empty(false); - rx.set_word_break_characters(word_break_characters); - } + rx.set_completion_callback(callback); + rx.set_complete_on_empty(false); + rx.set_word_break_characters(word_break_characters); #endif /// FIXME: check extender != delimiter }