From f793f5f8c5a424242247d3a57db2618726780ba4 Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Mon, 1 Nov 2021 19:06:23 +0300 Subject: [PATCH 1/8] Add list of hosts reading --- programs/client/Client.cpp | 5 +++-- programs/client/Client.h | 1 + src/Client/ClientBase.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 11459ff4a4a7..c4f071e2f2f4 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -512,6 +512,7 @@ catch (...) void Client::connect() { + config().setString("host", hosts[0]); connection_parameters = ConnectionParameters(config()); if (is_interactive) @@ -998,7 +999,7 @@ void Client::addAndCheckOptions(OptionsDescription & options_description, po::va /// Main commandline options related to client functionality and all parameters from Settings. options_description.main_description->add_options() ("config,c", po::value(), "config-file path (another shorthand)") - ("host,h", po::value()->default_value("localhost"), "server host") + ("host,h", po::value>()->multitoken()->default_value({"localhost"}, "localhost"), "list of server hosts") ("port", po::value()->default_value(9000), "server port") ("secure,s", "Use TLS connection") ("user,u", po::value()->default_value("default"), "user") @@ -1120,7 +1121,7 @@ void Client::processOptions(const OptionsDescription & options_description, if (options.count("config")) config().setString("config-file", options["config"].as()); if (options.count("host") && !options["host"].defaulted()) - config().setString("host", options["host"].as()); + hosts = options["host"].as>(); if (options.count("interleave-queries-file")) interleave_queries_files = options["interleave-queries-file"].as>(); if (options.count("pager")) diff --git a/programs/client/Client.h b/programs/client/Client.h index 43f6deae0b5e..2c092f9c9b64 100644 --- a/programs/client/Client.h +++ b/programs/client/Client.h @@ -29,6 +29,7 @@ class Client : public ClientBase const std::vector & external_tables_arguments) override; void processConfig() override; + std::vector hosts{}; private: void printChangedSettings() const; std::vector loadWarningMessages(); diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 7bcff4f5ef79..3395bef50644 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -1580,7 +1580,7 @@ void ClientBase::init(int argc, char ** argv) /// Output of help message. if (options.count("help") - || (options.count("host") && options["host"].as() == "elp")) /// If user writes -help instead of --help. + || (options.count("host") && options["host"].as>()[0] == "elp")) /// If user writes -help instead of --help. { printHelpMessage(options_description); exit(0); From 33b29e82f5ef3b17891903eb0768ee3757f5f7b7 Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Mon, 8 Nov 2021 18:53:05 +0300 Subject: [PATCH 2/8] Add list of ':[]' reading in --host param --- programs/client/Client.cpp | 322 ++++++++++++++++++++----------------- programs/client/Client.h | 11 +- src/Client/ClientBase.cpp | 2 +- src/Client/ClientBase.h | 18 +++ 4 files changed, 199 insertions(+), 154 deletions(-) diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index c4f071e2f2f4..b90077cad76a 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -1,20 +1,20 @@ -#include -#include -#include -#include -#include +#include "Client.h" +#include +#include #include #include -#include -#include +#include +#include #include +#include +#include +#include +#include +#include #include -#include #include +#include #include -#include -#include -#include "Client.h" #include "Core/Protocol.h" #include @@ -23,55 +23,55 @@ #if !defined(ARCADIA_BUILD) # include #endif +#include "Common/MemoryTracker.h" +#include +#include #include -#include #include -#include #include #include -#include -#include "Common/MemoryTracker.h" +#include -#include #include #include #include +#include #include +#include #include #include -#include -#include -#include #include +#include +#include #include #include -#include -#include +#include #include -#include #include -#include +#include +#include +#include #include #include -#include #include #include +#include #include "TestTags.h" #ifndef __clang__ -#pragma GCC optimize("-fno-var-tracking-assignments") +# pragma GCC optimize("-fno-var-tracking-assignments") #endif namespace CurrentMetrics { - extern const Metric Revision; - extern const Metric VersionInteger; - extern const Metric MemoryTracking; - extern const Metric MaxDDLEntryID; +extern const Metric Revision; +extern const Metric VersionInteger; +extern const Metric MemoryTracking; +extern const Metric MaxDDLEntryID; } namespace fs = std::filesystem; @@ -96,9 +96,11 @@ void Client::processError(const String & query) const if (server_exception) { bool print_stack_trace = config().getBool("stacktrace", false); - fmt::print(stderr, "Received exception from server (version {}):\n{}\n", - server_version, - getExceptionMessage(*server_exception, print_stack_trace, true)); + fmt::print( + stderr, + "Received exception from server (version {}):\n{}\n", + server_version, + getExceptionMessage(*server_exception, print_stack_trace, true)); if (is_interactive) { fmt::print(stderr, "\n"); @@ -165,21 +167,18 @@ bool Client::executeMultiQuery(const String & all_queries_text) while (true) { - auto stage = analyzeMultiQueryText(this_query_begin, this_query_end, all_queries_end, - query_to_execute, parsed_query, all_queries_text, current_exception); + auto stage = analyzeMultiQueryText( + this_query_begin, this_query_end, all_queries_end, query_to_execute, parsed_query, all_queries_text, current_exception); switch (stage) { case MultiQueryProcessingStage::QUERIES_END: - case MultiQueryProcessingStage::PARSING_FAILED: - { + case MultiQueryProcessingStage::PARSING_FAILED: { return true; } - case MultiQueryProcessingStage::CONTINUE_PARSING: - { + case MultiQueryProcessingStage::CONTINUE_PARSING: { continue; } - case MultiQueryProcessingStage::PARSING_EXCEPTION: - { + case MultiQueryProcessingStage::PARSING_EXCEPTION: { this_query_end = find_first_symbols<'\n'>(this_query_end, all_queries_end); // Try to find test hint for syntax error. We don't know where @@ -206,8 +205,7 @@ bool Client::executeMultiQuery(const String & all_queries_text) continue; } - case MultiQueryProcessingStage::EXECUTE_QUERY: - { + case MultiQueryProcessingStage::EXECUTE_QUERY: { full_query = all_queries_text.substr(this_query_begin - all_queries_text.data(), this_query_end - this_query_begin); if (query_fuzzer_runs) { @@ -247,14 +245,21 @@ bool Client::executeMultiQuery(const String & all_queries_text) if (!server_exception) { error_matches_hint = false; - fmt::print(stderr, "Expected server error code '{}' but got no server error (query: {}).\n", - test_hint.serverError(), full_query); + fmt::print( + stderr, + "Expected server error code '{}' but got no server error (query: {}).\n", + test_hint.serverError(), + full_query); } else if (server_exception->code() != test_hint.serverError()) { error_matches_hint = false; - fmt::print(stderr, "Expected server error code: {} but got: {} (query: {}).\n", - test_hint.serverError(), server_exception->code(), full_query); + fmt::print( + stderr, + "Expected server error code: {} but got: {} (query: {}).\n", + test_hint.serverError(), + server_exception->code(), + full_query); } } if (test_hint.clientError()) @@ -262,14 +267,21 @@ bool Client::executeMultiQuery(const String & all_queries_text) if (!client_exception) { error_matches_hint = false; - fmt::print(stderr, "Expected client error code '{}' but got no client error (query: {}).\n", - test_hint.clientError(), full_query); + fmt::print( + stderr, + "Expected client error code '{}' but got no client error (query: {}).\n", + test_hint.clientError(), + full_query); } else if (client_exception->code() != test_hint.clientError()) { error_matches_hint = false; - fmt::print(stderr, "Expected client error code '{}' but got '{}' (query: {}).\n", - test_hint.clientError(), client_exception->code(), full_query); + fmt::print( + stderr, + "Expected client error code '{}' but got '{}' (query: {}).\n", + test_hint.clientError(), + client_exception->code(), + full_query); } } if (!test_hint.clientError() && !test_hint.serverError()) @@ -284,14 +296,20 @@ bool Client::executeMultiQuery(const String & all_queries_text) { if (test_hint.clientError()) { - fmt::print(stderr, "The query succeeded but the client error '{}' was expected (query: {}).\n", - test_hint.clientError(), full_query); + fmt::print( + stderr, + "The query succeeded but the client error '{}' was expected (query: {}).\n", + test_hint.clientError(), + full_query); error_matches_hint = false; } if (test_hint.serverError()) { - fmt::print(stderr, "The query succeeded but the server error '{}' was expected (query: {}).\n", - test_hint.serverError(), full_query); + fmt::print( + stderr, + "The query succeeded but the server error '{}' was expected (query: {}).\n", + test_hint.serverError(), + full_query); error_matches_hint = false; } } @@ -339,8 +357,14 @@ bool Client::executeMultiQuery(const String & all_queries_text) std::vector Client::loadWarningMessages() { std::vector messages; - connection->sendQuery(connection_parameters.timeouts, "SELECT message FROM system.warnings", "" /* query_id */, - QueryProcessingStage::Complete, nullptr, nullptr, false); + connection->sendQuery( + connection_parameters.timeouts, + "SELECT message FROM system.warnings", + "" /* query_id */, + QueryProcessingStage::Complete, + nullptr, + nullptr, + false); while (true) { Packet packet = connection->receivePacket(); @@ -379,8 +403,8 @@ std::vector Client::loadWarningMessages() continue; default: - throw Exception(ErrorCodes::UNKNOWN_PACKET_FROM_SERVER, "Unknown packet {} from server {}", - packet.type, connection->getDescription()); + throw Exception( + ErrorCodes::UNKNOWN_PACKET_FROM_SERVER, "Unknown packet {} from server {}", packet.type, connection->getDescription()); } } } @@ -512,15 +536,13 @@ catch (...) void Client::connect() { - config().setString("host", hosts[0]); connection_parameters = ConnectionParameters(config()); if (is_interactive) std::cout << "Connecting to " - << (!connection_parameters.default_database.empty() ? "database " + connection_parameters.default_database + " at " - : "") - << connection_parameters.host << ":" << connection_parameters.port - << (!connection_parameters.user.empty() ? " as user " + connection_parameters.user : "") << "." << std::endl; + << (!connection_parameters.default_database.empty() ? "database " + connection_parameters.default_database + " at " : "") + << connection_parameters.host << ":" << connection_parameters.port + << (!connection_parameters.user.empty() ? " as user " + connection_parameters.user : "") << "." << std::endl; String server_name; UInt64 server_version_major = 0; @@ -547,18 +569,20 @@ void Client::connect() && e.code() == DB::ErrorCodes::AUTHENTICATION_FAILED) { std::cerr << std::endl - << "If you have installed ClickHouse and forgot password you can reset it in the configuration file." << std::endl - << "The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml" << std::endl - << "and deleting this file will reset the password." << std::endl - << "See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed." << std::endl - << std::endl; + << "If you have installed ClickHouse and forgot password you can reset it in the configuration file." << std::endl + << "The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml" + << std::endl + << "and deleting this file will reset the password." << std::endl + << "See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed." << std::endl + << std::endl; } throw; } server_version = toString(server_version_major) + "." + toString(server_version_minor) + "." + toString(server_version_patch); - load_suggestions = is_interactive && (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false)); + load_suggestions + = is_interactive && (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false)); if (server_display_name = connection->getServerDisplayName(connection_parameters.timeouts); server_display_name.empty()) server_display_name = config().getString("host", "localhost"); @@ -566,8 +590,8 @@ void Client::connect() if (is_interactive) { std::cout << "Connected to " << server_name << " server version " << server_version << " revision " << server_revision << "." - << std::endl - << std::endl; + << std::endl + << std::endl; auto client_version_tuple = std::make_tuple(VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); auto server_version_tuple = std::make_tuple(server_version_major, server_version_minor, server_version_patch); @@ -575,14 +599,14 @@ void Client::connect() if (client_version_tuple < server_version_tuple) { std::cout << "ClickHouse client version is older than ClickHouse server. " - << "It may lack support for new features." << std::endl - << std::endl; + << "It may lack support for new features." << std::endl + << std::endl; } else if (client_version_tuple > server_version_tuple) { std::cout << "ClickHouse server version is older than ClickHouse client. " - << "It may indicate that the server is out of date and can be upgraded." << std::endl - << std::endl; + << "It may indicate that the server is out of date and can be upgraded." << std::endl + << std::endl; } } @@ -598,16 +622,16 @@ void Client::connect() catch (...) { std::cerr << "Warning: could not switch to server time zone: " << time_zone - << ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl - << "Proceeding with local time zone." << std::endl - << std::endl; + << ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl + << "Proceeding with local time zone." << std::endl + << std::endl; } } else { std::cerr << "Warning: could not determine server time zone. " - << "Proceeding with local time zone." << std::endl - << std::endl; + << "Proceeding with local time zone." << std::endl + << std::endl; } } @@ -709,8 +733,7 @@ bool Client::processWithFuzzing(const String & full_query) } catch (const Exception & e) { - if (e.code() != ErrorCodes::SYNTAX_ERROR && - e.code() != ErrorCodes::TOO_DEEP_RECURSION) + if (e.code() != ErrorCodes::SYNTAX_ERROR && e.code() != ErrorCodes::TOO_DEEP_RECURSION) throw; } @@ -740,10 +763,7 @@ bool Client::processWithFuzzing(const String & full_query) // - SET -- The time to fuzz the settings has not yet come // (see comments in Client/QueryFuzzer.cpp) size_t this_query_runs = query_fuzzer_runs; - if (orig_ast->as() || - orig_ast->as() || - orig_ast->as() || - orig_ast->as()) + if (orig_ast->as() || orig_ast->as() || orig_ast->as() || orig_ast->as()) { this_query_runs = 1; } @@ -800,7 +820,9 @@ bool Client::processWithFuzzing(const String & full_query) fmt::print( stderr, - "Found error: IAST::clone() is broken for some AST node. This is a bug. The original AST ('dump before fuzz') and its cloned copy ('dump of cloned AST') refer to the same nodes, which must never happen. This means that their parent node doesn't implement clone() correctly."); + "Found error: IAST::clone() is broken for some AST node. This is a bug. The original AST ('dump before fuzz') and its " + "cloned copy ('dump of cloned AST') refer to the same nodes, which must never happen. This means that their parent " + "node doesn't implement clone() correctly."); exit(1); } @@ -855,9 +877,7 @@ bool Client::processWithFuzzing(const String & full_query) catch (...) { // Just report it, we'll terminate below. - fmt::print(stderr, - "Error while reconnecting to the server: {}\n", - getCurrentExceptionMessage(true)); + fmt::print(stderr, "Error while reconnecting to the server: {}\n", getCurrentExceptionMessage(true)); // The reconnection might fail, but we'll still be connected // in the sense of `connection->isConnected() = true`, @@ -922,8 +942,7 @@ bool Client::processWithFuzzing(const String & full_query) } catch (Exception & e) { - if (e.code() != ErrorCodes::SYNTAX_ERROR && - e.code() != ErrorCodes::TOO_DEEP_RECURSION) + if (e.code() != ErrorCodes::SYNTAX_ERROR && e.code() != ErrorCodes::TOO_DEEP_RECURSION) throw; } @@ -931,8 +950,7 @@ bool Client::processWithFuzzing(const String & full_query) { const auto text_2 = ast_2->formatForErrorMessage(); const auto * tmp_pos = text_2.c_str(); - const auto ast_3 = parseQuery(tmp_pos, tmp_pos + text_2.size(), - false /* allow_multi_statements */); + const auto ast_3 = parseQuery(tmp_pos, tmp_pos + text_2.size(), false /* allow_multi_statements */); const auto text_3 = ast_3->formatForErrorMessage(); if (text_3 != text_2) { @@ -940,9 +958,12 @@ bool Client::processWithFuzzing(const String & full_query) printChangedSettings(); - fmt::print(stderr, - "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, expected:\n'{}'\n", - text_3, text_2); + fmt::print( + stderr, + "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, " + "expected:\n'{}'\n", + text_3, + text_2); fmt::print(stderr, "In more detail:\n"); fmt::print(stderr, "AST-1 (generated by fuzzer):\n'{}'\n", parsed_query->dumpTree()); fmt::print(stderr, "Text-1 (AST-1 formatted):\n'{}'\n", query_to_execute); @@ -997,60 +1018,58 @@ void Client::printHelpMessage(const OptionsDescription & options_description) void Client::addAndCheckOptions(OptionsDescription & options_description, po::variables_map & options, Arguments & arguments) { /// Main commandline options related to client functionality and all parameters from Settings. - options_description.main_description->add_options() - ("config,c", po::value(), "config-file path (another shorthand)") - ("host,h", po::value>()->multitoken()->default_value({"localhost"}, "localhost"), "list of server hosts") - ("port", po::value()->default_value(9000), "server port") - ("secure,s", "Use TLS connection") - ("user,u", po::value()->default_value("default"), "user") + options_description.main_description->add_options()("config,c", po::value(), "config-file path (another shorthand)")( + "host,h", + po::value>()->multitoken()->default_value({{"localhost"}}, "localhost"), + "list of server hosts with optionally assigned port to connect. Every argument looks like '[:] for example" + "'localhost:port'. If port isn't assigned, connection is made by port from '--port' param")( + "port", po::value()->default_value(9000), "server default port")("secure,s", "Use TLS connection")( + "user,u", po::value()->default_value("default"), "user") /** If "--password [value]" is used but the value is omitted, the bad argument exception will be thrown. * implicit_value is used to avoid this exception (to allow user to type just "--password") * Since currently boost provides no way to check if a value has been set implicitly for an option, * the "\n" is used to distinguish this case because there is hardly a chance a user would use "\n" * as the password. */ - ("password", po::value()->implicit_value("\n", ""), "password") - ("ask-password", "ask-password") - ("quota_key", po::value(), "A string to differentiate quotas when the user have keyed quotas configured on server") - ("pager", po::value(), "pager") - ("testmode,T", "enable test hints in comments") - - ("max_client_network_bandwidth", po::value(), "the maximum speed of data exchange over the network for the client in bytes per second.") - ("compression", po::value(), "enable or disable compression") - - ("log-level", po::value(), "client log level") - ("server_logs_file", po::value(), "put server logs into specified file") - - ("query-fuzzer-runs", po::value()->default_value(0), "After executing every SELECT query, do random mutations in it and run again specified number of times. This is used for testing to discover unexpected corner cases.") - ("interleave-queries-file", po::value>()->multitoken(), - "file path with queries to execute before every file from 'queries-file'; multiple files can be specified (--queries-file file1 file2...); this is needed to enable more aggressive fuzzing of newly added tests (see 'query-fuzzer-runs' option)") - - ("opentelemetry-traceparent", po::value(), "OpenTelemetry traceparent header as described by W3C Trace Context recommendation") - ("opentelemetry-tracestate", po::value(), "OpenTelemetry tracestate header as described by W3C Trace Context recommendation") - - ("no-warnings", "disable warnings when client connects to server") - ("max_memory_usage_in_client", po::value(), "sets memory limit in client") - ; + ("password", po::value()->implicit_value("\n", ""), "password")("ask-password", "ask-password")( + "quota_key", po::value(), "A string to differentiate quotas when the user have keyed quotas configured on server")( + "pager", po::value(), "pager")("testmode,T", "enable test hints in comments") + + ("max_client_network_bandwidth", + po::value(), + "the maximum speed of data exchange over the network for the client in bytes per second.")( + "compression", po::value(), "enable or disable compression") + + ("log-level", po::value(), "client log level")( + "server_logs_file", po::value(), "put server logs into specified file") + + ("query-fuzzer-runs", + po::value()->default_value(0), + "After executing every SELECT query, do random mutations in it and run again specified number of times. This is used " + "for testing to discover unexpected corner cases.")( + "interleave-queries-file", + po::value>()->multitoken(), + "file path with queries to execute before every file from 'queries-file'; multiple files can be specified " + "(--queries-file file1 file2...); this is needed to enable more aggressive fuzzing of newly added tests (see " + "'query-fuzzer-runs' option)") + + ("opentelemetry-traceparent", + po::value(), + "OpenTelemetry traceparent header as described by W3C Trace Context recommendation")( + "opentelemetry-tracestate", + po::value(), + "OpenTelemetry tracestate header as described by W3C Trace Context recommendation") + + ("no-warnings", "disable warnings when client connects to server")( + "max_memory_usage_in_client", po::value(), "sets memory limit in client"); /// Commandline options related to external tables. options_description.external_description.emplace(createOptionsDescription("External tables options", terminal_width)); - options_description.external_description->add_options() - ( - "file", po::value(), "data file or - for stdin" - ) - ( - "name", po::value()->default_value("_data"), "name of the table" - ) - ( - "format", po::value()->default_value("TabSeparated"), "data format" - ) - ( - "structure", po::value(), "structure" - ) - ( - "types", po::value(), "types" - ); + options_description.external_description->add_options()("file", po::value(), "data file or - for stdin")( + "name", po::value()->default_value("_data"), "name of the table")( + "format", po::value()->default_value("TabSeparated"), "data format")( + "structure", po::value(), "structure")("types", po::value(), "types"); cmd_settings.addProgramOptions(options_description.main_description.value()); /// Parse main commandline options. @@ -1062,9 +1081,10 @@ void Client::addAndCheckOptions(OptionsDescription & options_description, po::va } -void Client::processOptions(const OptionsDescription & options_description, - const CommandLineOptions & options, - const std::vector & external_tables_arguments) +void Client::processOptions( + const OptionsDescription & options_description, + const CommandLineOptions & options, + const std::vector & external_tables_arguments) { namespace po = boost::program_options; @@ -1072,8 +1092,8 @@ void Client::processOptions(const OptionsDescription & options_description, for (size_t i = 0; i < external_tables_arguments.size(); ++i) { /// Parse commandline options related to external tables. - po::parsed_options parsed_tables = po::command_line_parser(external_tables_arguments[i]).options( - options_description.external_description.value()).run(); + po::parsed_options parsed_tables + = po::command_line_parser(external_tables_arguments[i]).options(options_description.external_description.value()).run(); po::variables_map external_options; po::store(parsed_tables, external_options); @@ -1121,7 +1141,12 @@ void Client::processOptions(const OptionsDescription & options_description, if (options.count("config")) config().setString("config-file", options["config"].as()); if (options.count("host") && !options["host"].defaulted()) - hosts = options["host"].as>(); + { + hosts_ports = options["host"].as>(); + config().setString("host", hosts_ports[0].host); + if (hosts_ports[0].port.has_value()) + config().setInt("port", hosts_ports[0].port.value()); + } if (options.count("interleave-queries-file")) interleave_queries_files = options["interleave-queries-file"].as>(); if (options.count("pager")) @@ -1215,7 +1240,8 @@ void Client::processConfig() if (global_context->getSettingsRef().max_insert_block_size.changed) insert_format_max_block_size = global_context->getSettingsRef().max_insert_block_size; else - insert_format_max_block_size = config().getInt("insert_format_max_block_size", global_context->getSettingsRef().max_insert_block_size); + insert_format_max_block_size + = config().getInt("insert_format_max_block_size", global_context->getSettingsRef().max_insert_block_size); ClientInfo & client_info = global_context->getClientInfo(); client_info.setInitialQuery(); diff --git a/programs/client/Client.h b/programs/client/Client.h index 2c092f9c9b64..61cab46e6f00 100644 --- a/programs/client/Client.h +++ b/programs/client/Client.h @@ -1,11 +1,11 @@ #pragma once #include - +#include +#include namespace DB { - class Client : public ClientBase { public: @@ -25,11 +25,12 @@ class Client : public ClientBase void printHelpMessage(const OptionsDescription & options_description) override; void addAndCheckOptions(OptionsDescription & options_description, po::variables_map & options, Arguments & arguments) override; - void processOptions(const OptionsDescription & options_description, const CommandLineOptions & options, - const std::vector & external_tables_arguments) override; + void processOptions( + const OptionsDescription & options_description, + const CommandLineOptions & options, + const std::vector & external_tables_arguments) override; void processConfig() override; - std::vector hosts{}; private: void printChangedSettings() const; std::vector loadWarningMessages(); diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 3395bef50644..9ed67bdc4f56 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -1580,7 +1580,7 @@ void ClientBase::init(int argc, char ** argv) /// Output of help message. if (options.count("help") - || (options.count("host") && options["host"].as>()[0] == "elp")) /// If user writes -help instead of --help. + || (options.count("host") && options["host"].as>()[0].host == "elp")) /// If user writes -help instead of --help. { printHelpMessage(options_description); exit(0); diff --git a/src/Client/ClientBase.h b/src/Client/ClientBase.h index fce706d7cf83..4c8e20d5735c 100644 --- a/src/Client/ClientBase.h +++ b/src/Client/ClientBase.h @@ -218,6 +218,24 @@ class ClientBase : public Poco::Util::Application int query_fuzzer_runs = 0; QueryProcessingStage::Enum query_processing_stage; + + struct HostPort + { + String host; + std::optional port{}; + friend std::istream & operator>>(std::istream & in, HostPort & hostPort) { + String + host_with_port, + delimiter = ":"; + in >> host_with_port; + size_t delimiter_pos = host_with_port.find(delimiter); + hostPort.host = host_with_port.substr(0, delimiter_pos); + if (delimiter_pos < host_with_port.length()) + hostPort.port = std::stoi(host_with_port.substr(delimiter_pos + 1, host_with_port.length())); + return in; + } + }; + std::vector hosts_ports{}; }; } From 7d34df6b8faab3a96dedcdf643acad63cc1d9b81 Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Mon, 8 Nov 2021 19:22:17 +0300 Subject: [PATCH 3/8] Delete extra includes --- programs/client/Client.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/programs/client/Client.h b/programs/client/Client.h index 61cab46e6f00..b805aebd5dbd 100644 --- a/programs/client/Client.h +++ b/programs/client/Client.h @@ -1,8 +1,6 @@ #pragma once #include -#include -#include namespace DB { From a7a8687c8595f14b6154ad1227e497d2b3d3af4a Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Mon, 8 Nov 2021 19:34:05 +0300 Subject: [PATCH 4/8] Revert changes in Client.h --- programs/client/Client.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/programs/client/Client.h b/programs/client/Client.h index b805aebd5dbd..43f6deae0b5e 100644 --- a/programs/client/Client.h +++ b/programs/client/Client.h @@ -2,8 +2,10 @@ #include + namespace DB { + class Client : public ClientBase { public: @@ -23,10 +25,8 @@ class Client : public ClientBase void printHelpMessage(const OptionsDescription & options_description) override; void addAndCheckOptions(OptionsDescription & options_description, po::variables_map & options, Arguments & arguments) override; - void processOptions( - const OptionsDescription & options_description, - const CommandLineOptions & options, - const std::vector & external_tables_arguments) override; + void processOptions(const OptionsDescription & options_description, const CommandLineOptions & options, + const std::vector & external_tables_arguments) override; void processConfig() override; private: From bb6c77d9cb3e83fda25beeacb49058847ed9614b Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Mon, 8 Nov 2021 21:42:07 +0300 Subject: [PATCH 5/8] Fix formatting --- programs/client/Client.cpp | 240 ++++++++++++++++--------------------- 1 file changed, 105 insertions(+), 135 deletions(-) diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index b90077cad76a..46eb52ab9453 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -1,20 +1,20 @@ -#include "Client.h" -#include -#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include -#include -#include -#include +#include +#include #include -#include #include +#include #include +#include +#include +#include "Client.h" #include "Core/Protocol.h" #include @@ -23,47 +23,47 @@ #if !defined(ARCADIA_BUILD) # include #endif -#include "Common/MemoryTracker.h" -#include -#include #include +#include #include +#include #include #include -#include +#include +#include "Common/MemoryTracker.h" +#include #include #include #include -#include #include -#include #include #include -#include -#include #include +#include +#include +#include #include #include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include #include +#include #include #include -#include #include "TestTags.h" #ifndef __clang__ -# pragma GCC optimize("-fno-var-tracking-assignments") +#pragma GCC optimize("-fno-var-tracking-assignments") #endif namespace CurrentMetrics @@ -96,11 +96,9 @@ void Client::processError(const String & query) const if (server_exception) { bool print_stack_trace = config().getBool("stacktrace", false); - fmt::print( - stderr, - "Received exception from server (version {}):\n{}\n", - server_version, - getExceptionMessage(*server_exception, print_stack_trace, true)); + fmt::print(stderr, "Received exception from server (version {}):\n{}\n", + server_version, + getExceptionMessage(*server_exception, print_stack_trace, true)); if (is_interactive) { fmt::print(stderr, "\n"); @@ -167,18 +165,21 @@ bool Client::executeMultiQuery(const String & all_queries_text) while (true) { - auto stage = analyzeMultiQueryText( - this_query_begin, this_query_end, all_queries_end, query_to_execute, parsed_query, all_queries_text, current_exception); + auto stage = analyzeMultiQueryText(this_query_begin, this_query_end, all_queries_end, + query_to_execute, parsed_query, all_queries_text, current_exception); switch (stage) { case MultiQueryProcessingStage::QUERIES_END: - case MultiQueryProcessingStage::PARSING_FAILED: { + case MultiQueryProcessingStage::PARSING_FAILED: + { return true; } - case MultiQueryProcessingStage::CONTINUE_PARSING: { + case MultiQueryProcessingStage::CONTINUE_PARSING: + { continue; } - case MultiQueryProcessingStage::PARSING_EXCEPTION: { + case MultiQueryProcessingStage::PARSING_EXCEPTION: + { this_query_end = find_first_symbols<'\n'>(this_query_end, all_queries_end); // Try to find test hint for syntax error. We don't know where @@ -205,7 +206,8 @@ bool Client::executeMultiQuery(const String & all_queries_text) continue; } - case MultiQueryProcessingStage::EXECUTE_QUERY: { + case MultiQueryProcessingStage::EXECUTE_QUERY: + { full_query = all_queries_text.substr(this_query_begin - all_queries_text.data(), this_query_end - this_query_begin); if (query_fuzzer_runs) { @@ -245,21 +247,14 @@ bool Client::executeMultiQuery(const String & all_queries_text) if (!server_exception) { error_matches_hint = false; - fmt::print( - stderr, - "Expected server error code '{}' but got no server error (query: {}).\n", - test_hint.serverError(), - full_query); + fmt::print(stderr, "Expected server error code '{}' but got no server error (query: {}).\n", + test_hint.serverError(), full_query); } else if (server_exception->code() != test_hint.serverError()) { error_matches_hint = false; - fmt::print( - stderr, - "Expected server error code: {} but got: {} (query: {}).\n", - test_hint.serverError(), - server_exception->code(), - full_query); + fmt::print(stderr, "Expected server error code: {} but got: {} (query: {}).\n", + test_hint.serverError(), server_exception->code(), full_query); } } if (test_hint.clientError()) @@ -267,21 +262,14 @@ bool Client::executeMultiQuery(const String & all_queries_text) if (!client_exception) { error_matches_hint = false; - fmt::print( - stderr, - "Expected client error code '{}' but got no client error (query: {}).\n", - test_hint.clientError(), - full_query); + fmt::print(stderr, "Expected client error code '{}' but got no client error (query: {}).\n", + test_hint.clientError(), full_query); } else if (client_exception->code() != test_hint.clientError()) { error_matches_hint = false; - fmt::print( - stderr, - "Expected client error code '{}' but got '{}' (query: {}).\n", - test_hint.clientError(), - client_exception->code(), - full_query); + fmt::print(stderr, "Expected client error code '{}' but got '{}' (query: {}).\n", + test_hint.clientError(), client_exception->code(), full_query); } } if (!test_hint.clientError() && !test_hint.serverError()) @@ -296,20 +284,14 @@ bool Client::executeMultiQuery(const String & all_queries_text) { if (test_hint.clientError()) { - fmt::print( - stderr, - "The query succeeded but the client error '{}' was expected (query: {}).\n", - test_hint.clientError(), - full_query); + fmt::print(stderr, "The query succeeded but the client error '{}' was expected (query: {}).\n", + test_hint.clientError(), full_query); error_matches_hint = false; } if (test_hint.serverError()) { - fmt::print( - stderr, - "The query succeeded but the server error '{}' was expected (query: {}).\n", - test_hint.serverError(), - full_query); + fmt::print(stderr, "The query succeeded but the server error '{}' was expected (query: {}).\n", + test_hint.serverError(), full_query); error_matches_hint = false; } } @@ -357,14 +339,8 @@ bool Client::executeMultiQuery(const String & all_queries_text) std::vector Client::loadWarningMessages() { std::vector messages; - connection->sendQuery( - connection_parameters.timeouts, - "SELECT message FROM system.warnings", - "" /* query_id */, - QueryProcessingStage::Complete, - nullptr, - nullptr, - false); + connection->sendQuery(connection_parameters.timeouts, "SELECT message FROM system.warnings", "" /* query_id */, + QueryProcessingStage::Complete, nullptr, nullptr, false); while (true) { Packet packet = connection->receivePacket(); @@ -403,8 +379,8 @@ std::vector Client::loadWarningMessages() continue; default: - throw Exception( - ErrorCodes::UNKNOWN_PACKET_FROM_SERVER, "Unknown packet {} from server {}", packet.type, connection->getDescription()); + throw Exception(ErrorCodes::UNKNOWN_PACKET_FROM_SERVER, "Unknown packet {} from server {}", + packet.type, connection->getDescription()); } } } @@ -540,7 +516,8 @@ void Client::connect() if (is_interactive) std::cout << "Connecting to " - << (!connection_parameters.default_database.empty() ? "database " + connection_parameters.default_database + " at " : "") + << (!connection_parameters.default_database.empty() ? "database " + connection_parameters.default_database + " at " + : "") << connection_parameters.host << ":" << connection_parameters.port << (!connection_parameters.user.empty() ? " as user " + connection_parameters.user : "") << "." << std::endl; @@ -570,8 +547,7 @@ void Client::connect() { std::cerr << std::endl << "If you have installed ClickHouse and forgot password you can reset it in the configuration file." << std::endl - << "The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml" - << std::endl + << "The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml" << std::endl << "and deleting this file will reset the password." << std::endl << "See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed." << std::endl << std::endl; @@ -581,8 +557,7 @@ void Client::connect() } server_version = toString(server_version_major) + "." + toString(server_version_minor) + "." + toString(server_version_patch); - load_suggestions - = is_interactive && (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false)); + load_suggestions = is_interactive && (server_revision >= Suggest::MIN_SERVER_REVISION && !config().getBool("disable_suggestion", false)); if (server_display_name = connection->getServerDisplayName(connection_parameters.timeouts); server_display_name.empty()) server_display_name = config().getString("host", "localhost"); @@ -733,7 +708,8 @@ bool Client::processWithFuzzing(const String & full_query) } catch (const Exception & e) { - if (e.code() != ErrorCodes::SYNTAX_ERROR && e.code() != ErrorCodes::TOO_DEEP_RECURSION) + if (e.code() != ErrorCodes::SYNTAX_ERROR && + e.code() != ErrorCodes::TOO_DEEP_RECURSION) throw; } @@ -763,7 +739,10 @@ bool Client::processWithFuzzing(const String & full_query) // - SET -- The time to fuzz the settings has not yet come // (see comments in Client/QueryFuzzer.cpp) size_t this_query_runs = query_fuzzer_runs; - if (orig_ast->as() || orig_ast->as() || orig_ast->as() || orig_ast->as()) + if (orig_ast->as() || + orig_ast->as() || + orig_ast->as() || + orig_ast->as()) { this_query_runs = 1; } @@ -820,9 +799,7 @@ bool Client::processWithFuzzing(const String & full_query) fmt::print( stderr, - "Found error: IAST::clone() is broken for some AST node. This is a bug. The original AST ('dump before fuzz') and its " - "cloned copy ('dump of cloned AST') refer to the same nodes, which must never happen. This means that their parent " - "node doesn't implement clone() correctly."); + "Found error: IAST::clone() is broken for some AST node. This is a bug. The original AST ('dump before fuzz') and its cloned copy ('dump of cloned AST') refer to the same nodes, which must never happen. This means that their parent node doesn't implement clone() correctly."); exit(1); } @@ -877,7 +854,9 @@ bool Client::processWithFuzzing(const String & full_query) catch (...) { // Just report it, we'll terminate below. - fmt::print(stderr, "Error while reconnecting to the server: {}\n", getCurrentExceptionMessage(true)); + fmt::print(stderr, + "Error while reconnecting to the server: {}\n", + getCurrentExceptionMessage(true)); // The reconnection might fail, but we'll still be connected // in the sense of `connection->isConnected() = true`, @@ -942,7 +921,8 @@ bool Client::processWithFuzzing(const String & full_query) } catch (Exception & e) { - if (e.code() != ErrorCodes::SYNTAX_ERROR && e.code() != ErrorCodes::TOO_DEEP_RECURSION) + if (e.code() != ErrorCodes::SYNTAX_ERROR && + e.code() != ErrorCodes::TOO_DEEP_RECURSION) throw; } @@ -950,7 +930,8 @@ bool Client::processWithFuzzing(const String & full_query) { const auto text_2 = ast_2->formatForErrorMessage(); const auto * tmp_pos = text_2.c_str(); - const auto ast_3 = parseQuery(tmp_pos, tmp_pos + text_2.size(), false /* allow_multi_statements */); + const auto ast_3 = parseQuery(tmp_pos, tmp_pos + text_2.size(), + false /* allow_multi_statements */); const auto text_3 = ast_3->formatForErrorMessage(); if (text_3 != text_2) { @@ -958,12 +939,9 @@ bool Client::processWithFuzzing(const String & full_query) printChangedSettings(); - fmt::print( - stderr, - "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, " - "expected:\n'{}'\n", - text_3, - text_2); + fmt::print(stderr, + "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, expected:\n'{}'\n", + text_3, text_2); fmt::print(stderr, "In more detail:\n"); fmt::print(stderr, "AST-1 (generated by fuzzer):\n'{}'\n", parsed_query->dumpTree()); fmt::print(stderr, "Text-1 (AST-1 formatted):\n'{}'\n", query_to_execute); @@ -1018,50 +996,42 @@ void Client::printHelpMessage(const OptionsDescription & options_description) void Client::addAndCheckOptions(OptionsDescription & options_description, po::variables_map & options, Arguments & arguments) { /// Main commandline options related to client functionality and all parameters from Settings. - options_description.main_description->add_options()("config,c", po::value(), "config-file path (another shorthand)")( - "host,h", - po::value>()->multitoken()->default_value({{"localhost"}}, "localhost"), - "list of server hosts with optionally assigned port to connect. Every argument looks like '[:] for example" - "'localhost:port'. If port isn't assigned, connection is made by port from '--port' param")( - "port", po::value()->default_value(9000), "server default port")("secure,s", "Use TLS connection")( - "user,u", po::value()->default_value("default"), "user") + options_description.main_description->add_options() + ("config,c", po::value(), "config-file path (another shorthand)") + ("host,h", po::value>()->multitoken()->default_value({{"localhost"}}, "localhost"), + "list of server hosts with optionally assigned port to connect. Every argument looks like '[:] for example" + "'localhost:port'. If port isn't assigned, connection is made by port from '--port' param") + ("port", po::value()->default_value(9000), "server port") + ("secure,s", "Use TLS connection") + ("user,u", po::value()->default_value("default"), "user") /** If "--password [value]" is used but the value is omitted, the bad argument exception will be thrown. * implicit_value is used to avoid this exception (to allow user to type just "--password") * Since currently boost provides no way to check if a value has been set implicitly for an option, * the "\n" is used to distinguish this case because there is hardly a chance a user would use "\n" * as the password. */ - ("password", po::value()->implicit_value("\n", ""), "password")("ask-password", "ask-password")( - "quota_key", po::value(), "A string to differentiate quotas when the user have keyed quotas configured on server")( - "pager", po::value(), "pager")("testmode,T", "enable test hints in comments") - - ("max_client_network_bandwidth", - po::value(), - "the maximum speed of data exchange over the network for the client in bytes per second.")( - "compression", po::value(), "enable or disable compression") - - ("log-level", po::value(), "client log level")( - "server_logs_file", po::value(), "put server logs into specified file") - - ("query-fuzzer-runs", - po::value()->default_value(0), - "After executing every SELECT query, do random mutations in it and run again specified number of times. This is used " - "for testing to discover unexpected corner cases.")( - "interleave-queries-file", - po::value>()->multitoken(), - "file path with queries to execute before every file from 'queries-file'; multiple files can be specified " - "(--queries-file file1 file2...); this is needed to enable more aggressive fuzzing of newly added tests (see " - "'query-fuzzer-runs' option)") - - ("opentelemetry-traceparent", - po::value(), - "OpenTelemetry traceparent header as described by W3C Trace Context recommendation")( - "opentelemetry-tracestate", - po::value(), - "OpenTelemetry tracestate header as described by W3C Trace Context recommendation") - - ("no-warnings", "disable warnings when client connects to server")( - "max_memory_usage_in_client", po::value(), "sets memory limit in client"); + ("password", po::value()->implicit_value("\n", ""), "password") + ("ask-password", "ask-password") + ("quota_key", po::value(), "A string to differentiate quotas when the user have keyed quotas configured on server") + ("pager", po::value(), "pager") + ("testmode,T", "enable test hints in comments") + + ("max_client_network_bandwidth", po::value(), "the maximum speed of data exchange over the network for the client in bytes per second.") + ("compression", po::value(), "enable or disable compression") + + ("log-level", po::value(), "client log level") + ("server_logs_file", po::value(), "put server logs into specified file") + + ("query-fuzzer-runs", po::value()->default_value(0), "After executing every SELECT query, do random mutations in it and run again specified number of times. This is used for testing to discover unexpected corner cases.") + ("interleave-queries-file", po::value>()->multitoken(), + "file path with queries to execute before every file from 'queries-file'; multiple files can be specified (--queries-file file1 file2...); this is needed to enable more aggressive fuzzing of newly added tests (see 'query-fuzzer-runs' option)") + + ("opentelemetry-traceparent", po::value(), "OpenTelemetry traceparent header as described by W3C Trace Context recommendation") + ("opentelemetry-tracestate", po::value(), "OpenTelemetry tracestate header as described by W3C Trace Context recommendation") + + ("no-warnings", "disable warnings when client connects to server") + ("max_memory_usage_in_client", po::value(), "sets memory limit in client") + ; /// Commandline options related to external tables. From 8125848c5a27428ebc20ccdf6f88c40503d87a81 Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Mon, 8 Nov 2021 21:50:06 +0300 Subject: [PATCH 6/8] Fix formatting --- programs/client/Client.cpp | 62 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 46eb52ab9453..2582b6979267 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -68,10 +68,10 @@ namespace CurrentMetrics { -extern const Metric Revision; -extern const Metric VersionInteger; -extern const Metric MemoryTracking; -extern const Metric MaxDDLEntryID; + extern const Metric Revision; + extern const Metric VersionInteger; + extern const Metric MemoryTracking; + extern const Metric MaxDDLEntryID; } namespace fs = std::filesystem; @@ -97,8 +97,8 @@ void Client::processError(const String & query) const { bool print_stack_trace = config().getBool("stacktrace", false); fmt::print(stderr, "Received exception from server (version {}):\n{}\n", - server_version, - getExceptionMessage(*server_exception, print_stack_trace, true)); + server_version, + getExceptionMessage(*server_exception, print_stack_trace, true)); if (is_interactive) { fmt::print(stderr, "\n"); @@ -380,7 +380,7 @@ std::vector Client::loadWarningMessages() default: throw Exception(ErrorCodes::UNKNOWN_PACKET_FROM_SERVER, "Unknown packet {} from server {}", - packet.type, connection->getDescription()); + packet.type, connection->getDescription()); } } } @@ -516,10 +516,10 @@ void Client::connect() if (is_interactive) std::cout << "Connecting to " - << (!connection_parameters.default_database.empty() ? "database " + connection_parameters.default_database + " at " + << (!connection_parameters.default_database.empty() ? "database " + connection_parameters.default_database + " at " : "") - << connection_parameters.host << ":" << connection_parameters.port - << (!connection_parameters.user.empty() ? " as user " + connection_parameters.user : "") << "." << std::endl; + << connection_parameters.host << ":" << connection_parameters.port + << (!connection_parameters.user.empty() ? " as user " + connection_parameters.user : "") << "." << std::endl; String server_name; UInt64 server_version_major = 0; @@ -546,11 +546,11 @@ void Client::connect() && e.code() == DB::ErrorCodes::AUTHENTICATION_FAILED) { std::cerr << std::endl - << "If you have installed ClickHouse and forgot password you can reset it in the configuration file." << std::endl - << "The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml" << std::endl - << "and deleting this file will reset the password." << std::endl - << "See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed." << std::endl - << std::endl; + << "If you have installed ClickHouse and forgot password you can reset it in the configuration file." << std::endl + << "The password for default user is typically located at /etc/clickhouse-server/users.d/default-password.xml" << std::endl + << "and deleting this file will reset the password." << std::endl + << "See also /etc/clickhouse-server/users.xml on the server where ClickHouse is installed." << std::endl + << std::endl; } throw; @@ -565,8 +565,8 @@ void Client::connect() if (is_interactive) { std::cout << "Connected to " << server_name << " server version " << server_version << " revision " << server_revision << "." - << std::endl - << std::endl; + << std::endl + << std::endl; auto client_version_tuple = std::make_tuple(VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); auto server_version_tuple = std::make_tuple(server_version_major, server_version_minor, server_version_patch); @@ -574,14 +574,14 @@ void Client::connect() if (client_version_tuple < server_version_tuple) { std::cout << "ClickHouse client version is older than ClickHouse server. " - << "It may lack support for new features." << std::endl - << std::endl; + << "It may lack support for new features." << std::endl + << std::endl; } else if (client_version_tuple > server_version_tuple) { std::cout << "ClickHouse server version is older than ClickHouse client. " - << "It may indicate that the server is out of date and can be upgraded." << std::endl - << std::endl; + << "It may indicate that the server is out of date and can be upgraded." << std::endl + << std::endl; } } @@ -597,16 +597,16 @@ void Client::connect() catch (...) { std::cerr << "Warning: could not switch to server time zone: " << time_zone - << ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl - << "Proceeding with local time zone." << std::endl - << std::endl; + << ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl + << "Proceeding with local time zone." << std::endl + << std::endl; } } else { std::cerr << "Warning: could not determine server time zone. " - << "Proceeding with local time zone." << std::endl - << std::endl; + << "Proceeding with local time zone." << std::endl + << std::endl; } } @@ -855,8 +855,8 @@ bool Client::processWithFuzzing(const String & full_query) { // Just report it, we'll terminate below. fmt::print(stderr, - "Error while reconnecting to the server: {}\n", - getCurrentExceptionMessage(true)); + "Error while reconnecting to the server: {}\n", + getCurrentExceptionMessage(true)); // The reconnection might fail, but we'll still be connected // in the sense of `connection->isConnected() = true`, @@ -931,7 +931,7 @@ bool Client::processWithFuzzing(const String & full_query) const auto text_2 = ast_2->formatForErrorMessage(); const auto * tmp_pos = text_2.c_str(); const auto ast_3 = parseQuery(tmp_pos, tmp_pos + text_2.size(), - false /* allow_multi_statements */); + false /* allow_multi_statements */); const auto text_3 = ast_3->formatForErrorMessage(); if (text_3 != text_2) { @@ -940,8 +940,8 @@ bool Client::processWithFuzzing(const String & full_query) printChangedSettings(); fmt::print(stderr, - "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, expected:\n'{}'\n", - text_3, text_2); + "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, expected:\n'{}'\n", + text_3, text_2); fmt::print(stderr, "In more detail:\n"); fmt::print(stderr, "AST-1 (generated by fuzzer):\n'{}'\n", parsed_query->dumpTree()); fmt::print(stderr, "Text-1 (AST-1 formatted):\n'{}'\n", query_to_execute); From 13329adcdf433751b65754787bcc67f7ae745444 Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Mon, 8 Nov 2021 21:52:45 +0300 Subject: [PATCH 7/8] Fix formatting --- programs/client/Client.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 2582b6979267..f32f1316ffbc 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -97,8 +97,8 @@ void Client::processError(const String & query) const { bool print_stack_trace = config().getBool("stacktrace", false); fmt::print(stderr, "Received exception from server (version {}):\n{}\n", - server_version, - getExceptionMessage(*server_exception, print_stack_trace, true)); + server_version, + getExceptionMessage(*server_exception, print_stack_trace, true)); if (is_interactive) { fmt::print(stderr, "\n"); @@ -517,7 +517,7 @@ void Client::connect() if (is_interactive) std::cout << "Connecting to " << (!connection_parameters.default_database.empty() ? "database " + connection_parameters.default_database + " at " - : "") + : "") << connection_parameters.host << ":" << connection_parameters.port << (!connection_parameters.user.empty() ? " as user " + connection_parameters.user : "") << "." << std::endl; @@ -940,8 +940,8 @@ bool Client::processWithFuzzing(const String & full_query) printChangedSettings(); fmt::print(stderr, - "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, expected:\n'{}'\n", - text_3, text_2); + "Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, expected:\n'{}'\n", + text_3, text_2); fmt::print(stderr, "In more detail:\n"); fmt::print(stderr, "AST-1 (generated by fuzzer):\n'{}'\n", parsed_query->dumpTree()); fmt::print(stderr, "Text-1 (AST-1 formatted):\n'{}'\n", query_to_execute); From 0bb2fb50039c73f31c03dba3f536a5597dd22d0a Mon Sep 17 00:00:00 2001 From: DF5HSE Date: Tue, 9 Nov 2021 00:43:34 +0300 Subject: [PATCH 8/8] Fix formatting --- programs/client/Client.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index f32f1316ffbc..b0388fb935ed 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -1036,10 +1036,22 @@ void Client::addAndCheckOptions(OptionsDescription & options_description, po::va /// Commandline options related to external tables. options_description.external_description.emplace(createOptionsDescription("External tables options", terminal_width)); - options_description.external_description->add_options()("file", po::value(), "data file or - for stdin")( - "name", po::value()->default_value("_data"), "name of the table")( - "format", po::value()->default_value("TabSeparated"), "data format")( - "structure", po::value(), "structure")("types", po::value(), "types"); + options_description.external_description->add_options() + ( + "file", po::value(), "data file or - for stdin" + ) + ( + "name", po::value()->default_value("_data"), "name of the table" + ) + ( + "format", po::value()->default_value("TabSeparated"), "data format" + ) + ( + "structure", po::value(), "structure" + ) + ( + "types", po::value(), "types" + ); cmd_settings.addProgramOptions(options_description.main_description.value()); /// Parse main commandline options. @@ -1051,10 +1063,9 @@ void Client::addAndCheckOptions(OptionsDescription & options_description, po::va } -void Client::processOptions( - const OptionsDescription & options_description, - const CommandLineOptions & options, - const std::vector & external_tables_arguments) +void Client::processOptions(const OptionsDescription & options_description, + const CommandLineOptions & options, + const std::vector & external_tables_arguments) { namespace po = boost::program_options; @@ -1062,8 +1073,8 @@ void Client::processOptions( for (size_t i = 0; i < external_tables_arguments.size(); ++i) { /// Parse commandline options related to external tables. - po::parsed_options parsed_tables - = po::command_line_parser(external_tables_arguments[i]).options(options_description.external_description.value()).run(); + po::parsed_options parsed_tables = po::command_line_parser(external_tables_arguments[i]).options( + options_description.external_description.value()).run(); po::variables_map external_options; po::store(parsed_tables, external_options); @@ -1210,8 +1221,7 @@ void Client::processConfig() if (global_context->getSettingsRef().max_insert_block_size.changed) insert_format_max_block_size = global_context->getSettingsRef().max_insert_block_size; else - insert_format_max_block_size - = config().getInt("insert_format_max_block_size", global_context->getSettingsRef().max_insert_block_size); + insert_format_max_block_size = config().getInt("insert_format_max_block_size", global_context->getSettingsRef().max_insert_block_size); ClientInfo & client_info = global_context->getClientInfo(); client_info.setInitialQuery();