From 5db1961129bc60969b44728481049321c3358c68 Mon Sep 17 00:00:00 2001 From: Ziy1-Tan Date: Wed, 31 May 2023 00:17:03 +0800 Subject: [PATCH 1/6] Allow specifying `--query` multiple times in the command line --- docs/en/interfaces/cli.md | 4 ++-- docs/ru/interfaces/cli.md | 2 +- docs/zh/interfaces/cli.md | 2 +- src/Client/ClientBase.cpp | 20 ++++++++-------- src/Client/ClientBase.h | 1 + ...771_specify_query_multiple_times.reference | 13 ++++++++++ .../02771_specify_query_multiple_times.sh | 24 +++++++++++++++++++ 7 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 tests/queries/0_stateless/02771_specify_query_multiple_times.reference create mode 100755 tests/queries/0_stateless/02771_specify_query_multiple_times.sh diff --git a/docs/en/interfaces/cli.md b/docs/en/interfaces/cli.md index 36afb94433a..175ff858d09 100644 --- a/docs/en/interfaces/cli.md +++ b/docs/en/interfaces/cli.md @@ -30,7 +30,7 @@ It may lack support for new features. ## Usage {#cli_usage} -The client can be used in interactive and non-interactive (batch) mode. +The client can be used in interactive and non-interactive (batch) mode. ### Gather your connection details @@ -177,7 +177,7 @@ You can pass parameters to `clickhouse-client` (all parameters have a default va - `--user, -u` – The username. Default value: default. - `--password` – The password. Default value: empty string. - `--ask-password` - Prompt the user to enter a password. -- `--query, -q` – The query to process when using non-interactive mode. Cannot be used simultaneously with `--queries-file`. +- `--query, -q` – The query to process when using non-interactive mode. Specifying `--query` multiple times are allowed(`--query "SELECT 1;" --query "SELECT 2;"...`). Cannot be used simultaneously with `--queries-file`. - `--queries-file` – file path with queries to execute. Cannot be used simultaneously with `--query`. - `--multiquery, -n` – If specified, multiple queries separated by semicolons can be listed after the `--query` option. For convenience, it is also possible to omit `--query` and pass the queries directly after `--multiquery`. - `--multiline, -m` – If specified, allow multiline queries (do not send the query on Enter). diff --git a/docs/ru/interfaces/cli.md b/docs/ru/interfaces/cli.md index aa6ae3629e8..47ab6474fc0 100644 --- a/docs/ru/interfaces/cli.md +++ b/docs/ru/interfaces/cli.md @@ -128,7 +128,7 @@ $ clickhouse-client --param_tbl="numbers" --param_db="system" --param_col="numbe - `--port` — порт для подключения, по умолчанию — 9000. Обратите внимание: для HTTP-интерфейса и нативного интерфейса используются разные порты. - `--user, -u` — имя пользователя, по умолчанию — ‘default’. - `--password` — пароль, по умолчанию — пустая строка. -- `--query, -q` — запрос для выполнения, при использовании в неинтерактивном режиме. +- `--query, -q` — запрос для выполнения, при использовании в неинтерактивном режиме. Допускается указание `--query` несколько раз (`--query "SELECT 1;" --query "SELECT 2;"...`). - `--queries-file` - путь к файлу с запросами для выполнения. Необходимо указать только одну из опций: `query` или `queries-file`. - `--database, -d` — выбрать текущую БД. Без указания значение берется из настроек сервера (по умолчанию — БД ‘default’). - `--multiline, -m` — если указано — разрешить многострочные запросы, не отправлять запрос по нажатию Enter. diff --git a/docs/zh/interfaces/cli.md b/docs/zh/interfaces/cli.md index 80d13154a76..a6b4d10dd2f 100644 --- a/docs/zh/interfaces/cli.md +++ b/docs/zh/interfaces/cli.md @@ -116,7 +116,7 @@ $ clickhouse-client --param_tuple_in_tuple="(10, ('dt', 10))" -q "SELECT * FROM - `--port` – 连接的端口,默认值:9000。注意HTTP接口以及TCP原生接口使用的是不同端口。 - `--user, -u` – 用户名。 默认值:`default`。 - `--password` – 密码。 默认值:空字符串。 -- `--query, -q` – 使用非交互模式查询。 +- `--query, -q` – 使用非交互模式查询。 允许多次指定 `--query`(`--query "SELECT 1;" --query "SELECT 2;"...`)。 - `--database, -d` – 默认当前操作的数据库. 默认值:服务端默认的配置(默认是`default`)。 - `--multiline, -m` – 如果指定,允许多行语句查询(Enter仅代表换行,不代表查询语句完结)。 - `--multiquery, -n` – 如果指定, 允许处理用`;`号分隔的多个查询,只在非交互模式下生效。 diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 19244134617..46d6e882d2f 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -2484,23 +2484,23 @@ void ClientBase::runNonInteractive() return; } - String text; - if (config().has("query")) + if (!queries.empty()) { - text += config().getRawString("query"); /// Poco configuration should not process substitutions in form of ${...} inside query. + for (const auto & query : queries) + { + bool result = query_fuzzer_runs ? processWithFuzzing(query) : processQueryText(query); + if (!result) + return; + } } else { /// If 'query' parameter is not set, read a query from stdin. /// The query is read entirely into memory (streaming is disabled). ReadBufferFromFileDescriptor in(STDIN_FILENO); + String text; readStringUntilEOF(text, in); } - - if (query_fuzzer_runs) - processWithFuzzing(text); - else - processQueryText(text); } @@ -2700,7 +2700,7 @@ void ClientBase::init(int argc, char ** argv) ("config-file,C", po::value(), "config-file path") - ("query,q", po::value(), "query") + ("query,q", po::value>(), R"(query; specifying --query multiple times are allowed(--query "SELECT 1;" --query "SELECT 2;"...))") ("queries-file", po::value>()->multitoken(), "file path with queries to execute; multiple files can be specified (--queries-file file1 file2...)") ("multiquery,n", "If specified, multiple queries separated by semicolons can be listed after --query. For convenience, it is also possible to omit --query and pass the queries directly after --multiquery.") @@ -2789,7 +2789,7 @@ void ClientBase::init(int argc, char ** argv) if (options.count("time")) print_time_to_stderr = true; if (options.count("query")) - config().setString("query", options["query"].as()); + queries = options["query"].as>(); if (options.count("query_id")) config().setString("query_id", options["query_id"].as()); if (options.count("database")) diff --git a/src/Client/ClientBase.h b/src/Client/ClientBase.h index d877905302d..9a2a78a2b38 100644 --- a/src/Client/ClientBase.h +++ b/src/Client/ClientBase.h @@ -202,6 +202,7 @@ protected: std::optional suggest; bool load_suggestions = false; + std::vector queries; /// If not empty, queries will be read from these strings std::vector queries_files; /// If not empty, queries will be read from these files std::vector interleave_queries_files; /// If not empty, run queries from these files before processing every file from 'queries_files'. std::vector cmd_options; diff --git a/tests/queries/0_stateless/02771_specify_query_multiple_times.reference b/tests/queries/0_stateless/02771_specify_query_multiple_times.reference new file mode 100644 index 00000000000..18a0b6bde4d --- /dev/null +++ b/tests/queries/0_stateless/02771_specify_query_multiple_times.reference @@ -0,0 +1,13 @@ +101 +202 +303 +404 +404 +404 +505 +Syntax error +Syntax error +Empty query +Empty query +BAD_ARGUMENTS +Bad arguments diff --git a/tests/queries/0_stateless/02771_specify_query_multiple_times.sh b/tests/queries/0_stateless/02771_specify_query_multiple_times.sh new file mode 100755 index 00000000000..e477b0deef9 --- /dev/null +++ b/tests/queries/0_stateless/02771_specify_query_multiple_times.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +$CLICKHOUSE_LOCAL --query "SELECT 101" +$CLICKHOUSE_LOCAL --query "SELECT 202" --query "SELECT 303" +$CLICKHOUSE_LOCAL --query "SELECT 404" --query "SELECT 404" --query "SELECT 404" +$CLICKHOUSE_LOCAL --query --query 2>&1 +$CLICKHOUSE_LOCAL --query "" --query "" 2>&1 +$CLICKHOUSE_LOCAL --query "SELECT 505;"--query + +# Abort if any invalid SQL +$CLICKHOUSE_LOCAL --query "SELECT 606; S" --query "SELECT 606" 2>&1 | grep -o 'Syntax error' +$CLICKHOUSE_LOCAL --query "SELECT 707" --query "SELECT 808; S" 2>&1 | grep -o '201' +$CLICKHOUSE_LOCAL --query "SELECT 909" --query "SELECT 909; S" 2>&1 | grep -o 'Syntax error' +$CLICKHOUSE_LOCAL --query "; SELECT 111;" --query "SELECT 111;" 2>&1 | grep -o 'Empty query' +$CLICKHOUSE_LOCAL --query "SELECT 222;" --query "; SELECT 222;" 2>&1 | grep -o '201' +$CLICKHOUSE_LOCAL --query "SELECT 333;" --query "; SELECT 333;" 2>&1 | grep -o 'Empty query' + + +$CLICKHOUSE_LOCAL --query --query "SELECT 444;" 2>&1 | grep -o 'BAD_ARGUMENTS' +$CLICKHOUSE_LOCAL --query "SELECT 555;" --query 2>&1 | grep -o 'Bad arguments' From fe7d636b935da44b706e3a7fb2fbcf524481f337 Mon Sep 17 00:00:00 2001 From: Ziy1-Tan Date: Wed, 31 May 2023 09:40:31 +0800 Subject: [PATCH 2/6] Improve docs Signed-off-by: Ziy1-Tan --- docs/en/interfaces/cli.md | 2 +- src/Client/ClientBase.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/interfaces/cli.md b/docs/en/interfaces/cli.md index 175ff858d09..ab04e3352bd 100644 --- a/docs/en/interfaces/cli.md +++ b/docs/en/interfaces/cli.md @@ -177,7 +177,7 @@ You can pass parameters to `clickhouse-client` (all parameters have a default va - `--user, -u` – The username. Default value: default. - `--password` – The password. Default value: empty string. - `--ask-password` - Prompt the user to enter a password. -- `--query, -q` – The query to process when using non-interactive mode. Specifying `--query` multiple times are allowed(`--query "SELECT 1;" --query "SELECT 2;"...`). Cannot be used simultaneously with `--queries-file`. +- `--query, -q` – The query to process when using non-interactive mode. Specifying `--query` multiple times is allowed (`--query "SELECT 1;" --query "SELECT 2;"...`). Cannot be used simultaneously with `--queries-file`. - `--queries-file` – file path with queries to execute. Cannot be used simultaneously with `--query`. - `--multiquery, -n` – If specified, multiple queries separated by semicolons can be listed after the `--query` option. For convenience, it is also possible to omit `--query` and pass the queries directly after `--multiquery`. - `--multiline, -m` – If specified, allow multiline queries (do not send the query on Enter). diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 46d6e882d2f..934394601f2 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -2700,7 +2700,7 @@ void ClientBase::init(int argc, char ** argv) ("config-file,C", po::value(), "config-file path") - ("query,q", po::value>(), R"(query; specifying --query multiple times are allowed(--query "SELECT 1;" --query "SELECT 2;"...))") + ("query,q", po::value>(), R"(query; can be specified multiple times (--query "SELECT 1;" --query "SELECT 2;"...))") ("queries-file", po::value>()->multitoken(), "file path with queries to execute; multiple files can be specified (--queries-file file1 file2...)") ("multiquery,n", "If specified, multiple queries separated by semicolons can be listed after --query. For convenience, it is also possible to omit --query and pass the queries directly after --multiquery.") From 44994fe51be89f4f2d831ca887581d30a4996382 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Mon, 4 Sep 2023 11:40:56 +0000 Subject: [PATCH 3/6] Incorporate review feedback --- docs/en/interfaces/cli.md | 4 +-- .../operations/utilities/clickhouse-local.md | 4 +-- src/Client/ClientBase.cpp | 25 +++++++++++++------ src/Client/ClientBase.h | 2 +- .../02771_multiple_query_arguments.reference | 17 +++++++++++++ .../02771_multiple_query_arguments.sh | 21 ++++++++++++++++ ...771_specify_query_multiple_times.reference | 13 ---------- .../02771_specify_query_multiple_times.sh | 24 ------------------ 8 files changed, 60 insertions(+), 50 deletions(-) create mode 100644 tests/queries/0_stateless/02771_multiple_query_arguments.reference create mode 100755 tests/queries/0_stateless/02771_multiple_query_arguments.sh delete mode 100644 tests/queries/0_stateless/02771_specify_query_multiple_times.reference delete mode 100755 tests/queries/0_stateless/02771_specify_query_multiple_times.sh diff --git a/docs/en/interfaces/cli.md b/docs/en/interfaces/cli.md index ab04e3352bd..f018f3a248e 100644 --- a/docs/en/interfaces/cli.md +++ b/docs/en/interfaces/cli.md @@ -177,8 +177,8 @@ You can pass parameters to `clickhouse-client` (all parameters have a default va - `--user, -u` – The username. Default value: default. - `--password` – The password. Default value: empty string. - `--ask-password` - Prompt the user to enter a password. -- `--query, -q` – The query to process when using non-interactive mode. Specifying `--query` multiple times is allowed (`--query "SELECT 1;" --query "SELECT 2;"...`). Cannot be used simultaneously with `--queries-file`. -- `--queries-file` – file path with queries to execute. Cannot be used simultaneously with `--query`. +- `--query, -q` – The query to process when using non-interactive mode. `--query` can be specified multiple times, e.g. `--query "SELECT 1" --query "SELECT 2"`. Cannot be used simultaneously with `--queries-file`. +- `--queries-file` – file path with queries to execute. `--queries-file` can be specified multiple times, e.g. `--query queries1.sql --query queries2.sql`. Cannot be used simultaneously with `--query`. - `--multiquery, -n` – If specified, multiple queries separated by semicolons can be listed after the `--query` option. For convenience, it is also possible to omit `--query` and pass the queries directly after `--multiquery`. - `--multiline, -m` – If specified, allow multiline queries (do not send the query on Enter). - `--database, -d` – Select the current default database. Default value: the current database from the server settings (‘default’ by default). diff --git a/docs/en/operations/utilities/clickhouse-local.md b/docs/en/operations/utilities/clickhouse-local.md index 737c2b81dee..c863282efc1 100644 --- a/docs/en/operations/utilities/clickhouse-local.md +++ b/docs/en/operations/utilities/clickhouse-local.md @@ -202,8 +202,8 @@ Arguments: - `-S`, `--structure` — table structure for input data. - `--input-format` — input format, `TSV` by default. - `-f`, `--file` — path to data, `stdin` by default. -- `-q`, `--query` — queries to execute with `;` as delimiter. Cannot be used simultaneously with `--queries-file`. -- `--queries-file` - file path with queries to execute. Cannot be used simultaneously with `--query`. +- `-q`, `--query` — queries to execute with `;` as delimiter. `--query` can be specified multiple times, e.g. `--query "SELECT 1" --query "SELECT 2"`. Cannot be used simultaneously with `--queries-file`. +- `--queries-file` - file path with queries to execute. `--queries-file` can be specified multiple times, e.g. `--query queries1.sql --query queries2.sql`. Cannot be used simultaneously with `--query`. - `--multiquery, -n` – If specified, multiple queries separated by semicolons can be listed after the `--query` option. For convenience, it is also possible to omit `--query` and pass the queries directly after `--multiquery`. - `-N`, `--table` — table name where to put output data, `table` by default. - `--format`, `--output-format` — output format, `TSV` by default. diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 934394601f2..64fd37cc90d 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -2488,9 +2488,16 @@ void ClientBase::runNonInteractive() { for (const auto & query : queries) { - bool result = query_fuzzer_runs ? processWithFuzzing(query) : processQueryText(query); - if (!result) - return; + if (query_fuzzer_runs) + { + if (!processWithFuzzing(query)) + return; + } + else + { + if (!processQueryText(query)) + return; + } } } else @@ -2500,6 +2507,10 @@ void ClientBase::runNonInteractive() ReadBufferFromFileDescriptor in(STDIN_FILENO); String text; readStringUntilEOF(text, in); + if (query_fuzzer_runs) + processWithFuzzing(text); + else + processQueryText(text); } } @@ -2700,9 +2711,8 @@ void ClientBase::init(int argc, char ** argv) ("config-file,C", po::value(), "config-file path") - ("query,q", po::value>(), R"(query; can be specified multiple times (--query "SELECT 1;" --query "SELECT 2;"...))") - ("queries-file", po::value>()->multitoken(), - "file path with queries to execute; multiple files can be specified (--queries-file file1 file2...)") + ("query,q", po::value>(), R"(query; can be specified multiple times (--query "SELECT 1" --query "SELECT 2"...))") + ("queries-file", po::value>()->multitoken(), "file path with queries to execute; multiple files can be specified (--queries-file file1 file2...)") ("multiquery,n", "If specified, multiple queries separated by semicolons can be listed after --query. For convenience, it is also possible to omit --query and pass the queries directly after --multiquery.") ("multiline,m", "If specified, allow multiline queries (do not send the query on Enter)") ("database,d", po::value(), "database") @@ -2723,8 +2733,7 @@ void ClientBase::init(int argc, char ** argv) ("log-level", po::value(), "log level") ("server_logs_file", po::value(), "put server logs into specified file") - ("suggestion_limit", po::value()->default_value(10000), - "Suggestion limit for how many databases, tables and columns to fetch.") + ("suggestion_limit", po::value()->default_value(10000), "Suggestion limit for how many databases, tables and columns to fetch.") ("format,f", po::value(), "default output format") ("vertical,E", "vertical output format, same as --format=Vertical or FORMAT Vertical or \\G at end of command") diff --git a/src/Client/ClientBase.h b/src/Client/ClientBase.h index 9a2a78a2b38..eabc79b7432 100644 --- a/src/Client/ClientBase.h +++ b/src/Client/ClientBase.h @@ -202,7 +202,7 @@ protected: std::optional suggest; bool load_suggestions = false; - std::vector queries; /// If not empty, queries will be read from these strings + std::vector queries; /// Queries passed via '--query' std::vector queries_files; /// If not empty, queries will be read from these files std::vector interleave_queries_files; /// If not empty, run queries from these files before processing every file from 'queries_files'. std::vector cmd_options; diff --git a/tests/queries/0_stateless/02771_multiple_query_arguments.reference b/tests/queries/0_stateless/02771_multiple_query_arguments.reference new file mode 100644 index 00000000000..5cad23947c8 --- /dev/null +++ b/tests/queries/0_stateless/02771_multiple_query_arguments.reference @@ -0,0 +1,17 @@ +101 +101 +202 +202 +Multi-statements are not allowed +Empty query +Bad arguments +Syntax error +101 +101 +202 +202 +303 +303 +303 +Bad arguments +Syntax error diff --git a/tests/queries/0_stateless/02771_multiple_query_arguments.sh b/tests/queries/0_stateless/02771_multiple_query_arguments.sh new file mode 100755 index 00000000000..435e0a33315 --- /dev/null +++ b/tests/queries/0_stateless/02771_multiple_query_arguments.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +# clickhouse-client +$CLICKHOUSE_CLIENT --query "SELECT 101" --query "SELECT 101" +$CLICKHOUSE_CLIENT --query "SELECT 202;" --query "SELECT 202;" +$CLICKHOUSE_CLIENT --query "SELECT 303" --query "SELECT 303; SELECT 303" 2>&1 | grep -o 'Multi-statements are not allowed' +$CLICKHOUSE_CLIENT --query "" --query "" 2>&1 | grep -o 'Empty query' +$CLICKHOUSE_CLIENT --query "SELECT 303" --query 2>&1 | grep -o 'Bad arguments' +$CLICKHOUSE_CLIENT --query "SELECT 303" --query "SELE" 2>&1 | grep -o 'Syntax error' + +# clickhouse-local +$CLICKHOUSE_LOCAL --query "SELECT 101" --query "SELECT 101" +$CLICKHOUSE_LOCAL --query "SELECT 202;" --query "SELECT 202;" +$CLICKHOUSE_LOCAL --query "SELECT 303" --query "SELECT 303; SELECT 303" 2>&1 # behaves differently than clickhouse-client, TODO make it consistent +$CLICKHOUSE_LOCAL --query "" --query "" 2>&1 # behaves equally different than clickhouse-client TODO +$CLICKHOUSE_LOCAL --query "SELECT 303" --query 2>&1 | grep -o 'Bad arguments' +$CLICKHOUSE_LOCAL --query "SELECT 303" --query "SELE" 2>&1 | grep -o 'Syntax error' diff --git a/tests/queries/0_stateless/02771_specify_query_multiple_times.reference b/tests/queries/0_stateless/02771_specify_query_multiple_times.reference deleted file mode 100644 index 18a0b6bde4d..00000000000 --- a/tests/queries/0_stateless/02771_specify_query_multiple_times.reference +++ /dev/null @@ -1,13 +0,0 @@ -101 -202 -303 -404 -404 -404 -505 -Syntax error -Syntax error -Empty query -Empty query -BAD_ARGUMENTS -Bad arguments diff --git a/tests/queries/0_stateless/02771_specify_query_multiple_times.sh b/tests/queries/0_stateless/02771_specify_query_multiple_times.sh deleted file mode 100755 index e477b0deef9..00000000000 --- a/tests/queries/0_stateless/02771_specify_query_multiple_times.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -# shellcheck source=../shell_config.sh -. "$CURDIR"/../shell_config.sh - -$CLICKHOUSE_LOCAL --query "SELECT 101" -$CLICKHOUSE_LOCAL --query "SELECT 202" --query "SELECT 303" -$CLICKHOUSE_LOCAL --query "SELECT 404" --query "SELECT 404" --query "SELECT 404" -$CLICKHOUSE_LOCAL --query --query 2>&1 -$CLICKHOUSE_LOCAL --query "" --query "" 2>&1 -$CLICKHOUSE_LOCAL --query "SELECT 505;"--query - -# Abort if any invalid SQL -$CLICKHOUSE_LOCAL --query "SELECT 606; S" --query "SELECT 606" 2>&1 | grep -o 'Syntax error' -$CLICKHOUSE_LOCAL --query "SELECT 707" --query "SELECT 808; S" 2>&1 | grep -o '201' -$CLICKHOUSE_LOCAL --query "SELECT 909" --query "SELECT 909; S" 2>&1 | grep -o 'Syntax error' -$CLICKHOUSE_LOCAL --query "; SELECT 111;" --query "SELECT 111;" 2>&1 | grep -o 'Empty query' -$CLICKHOUSE_LOCAL --query "SELECT 222;" --query "; SELECT 222;" 2>&1 | grep -o '201' -$CLICKHOUSE_LOCAL --query "SELECT 333;" --query "; SELECT 333;" 2>&1 | grep -o 'Empty query' - - -$CLICKHOUSE_LOCAL --query --query "SELECT 444;" 2>&1 | grep -o 'BAD_ARGUMENTS' -$CLICKHOUSE_LOCAL --query "SELECT 555;" --query 2>&1 | grep -o 'Bad arguments' From 11fea581bcf1c2816983a76c362f51b1fbd37f2c Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Mon, 4 Sep 2023 14:48:38 +0000 Subject: [PATCH 4/6] Fix tests --- programs/client/Client.cpp | 6 +++--- programs/local/LocalServer.cpp | 10 +++++----- src/Client/ClientBase.cpp | 6 +++--- .../02751_multiquery_with_argument.reference | 3 --- .../0_stateless/02751_multiquery_with_argument.sh | 5 +---- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 929e59ed852..64823f9ec7f 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -1189,7 +1189,7 @@ void Client::processOptions(const OptionsDescription & options_description, void Client::processConfig() { - if (config().has("query") && config().has("queries-file")) + if (!queries.empty() && config().has("queries-file")) throw Exception(ErrorCodes::BAD_ARGUMENTS, "Options '--query' and '--queries-file' cannot be specified at the same time"); /// Batch mode is enabled if one of the following is true: @@ -1200,9 +1200,9 @@ void Client::processConfig() /// - --queries-file command line option is present. /// The value of the option is used as file with query (or of multiple queries) to execute. - delayed_interactive = config().has("interactive") && (config().has("query") || config().has("queries-file")); + delayed_interactive = config().has("interactive") && (!queries.empty() || config().has("queries-file")); if (stdin_is_a_tty - && (delayed_interactive || (!config().has("query") && queries_files.empty()))) + && (delayed_interactive || (queries.empty() && queries_files.empty()))) { is_interactive = true; } diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 5c522b678ef..cacfe4dc162 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -319,7 +319,7 @@ static bool checkIfStdinIsRegularFile() std::string LocalServer::getInitialCreateTableQuery() { - if (!config().has("table-structure") && !config().has("table-file") && !config().has("table-data-format") && (!checkIfStdinIsRegularFile() || !config().has("query"))) + if (!config().has("table-structure") && !config().has("table-file") && !config().has("table-data-format") && (!checkIfStdinIsRegularFile() || queries.empty())) return {}; auto table_name = backQuoteIfNeed(config().getString("table-name", "table")); @@ -461,7 +461,7 @@ try if (first_time) { - if (queries_files.empty() && !config().has("query")) + if (queries_files.empty() && queries.empty()) { std::cerr << "\033[31m" << "ClickHouse compiled in fuzzing mode." << "\033[0m" << std::endl; std::cerr << "\033[31m" << "You have to provide a query with --query or --queries-file option." << "\033[0m" << std::endl; @@ -473,7 +473,7 @@ try #else is_interactive = stdin_is_a_tty && (config().hasOption("interactive") - || (!config().has("query") && !config().has("table-structure") && queries_files.empty() && !config().has("table-file"))); + || (queries.empty() && !config().has("table-structure") && queries_files.empty() && !config().has("table-file"))); #endif if (!is_interactive) { @@ -569,10 +569,10 @@ void LocalServer::updateLoggerLevel(const String & logs_level) void LocalServer::processConfig() { - if (config().has("query") && config().has("queries-file")) + if (!queries.empty() && config().has("queries-file")) throw Exception(ErrorCodes::BAD_ARGUMENTS, "Options '--query' and '--queries-file' cannot be specified at the same time"); - delayed_interactive = config().has("interactive") && (config().has("query") || config().has("queries-file")); + delayed_interactive = config().has("interactive") && (!queries.empty() || config().has("queries-file")); if (is_interactive && !delayed_interactive) { if (config().has("multiquery")) diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 64fd37cc90d..7d34e65356e 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -2680,8 +2680,8 @@ void ClientBase::init(int argc, char ** argv) stderr_is_a_tty = isatty(STDERR_FILENO); terminal_width = getTerminalWidth(); - Arguments common_arguments{""}; /// 0th argument is ignored. std::vector external_tables_arguments; + Arguments common_arguments = {""}; /// 0th argument is ignored. std::vector hosts_and_ports_arguments; readArguments(argc, argv, common_arguments, external_tables_arguments, hosts_and_ports_arguments); @@ -2699,7 +2699,6 @@ void ClientBase::init(int argc, char ** argv) } - po::variables_map options; OptionsDescription options_description; options_description.main_description.emplace(createOptionsDescription("Main options", terminal_width)); @@ -2711,7 +2710,7 @@ void ClientBase::init(int argc, char ** argv) ("config-file,C", po::value(), "config-file path") - ("query,q", po::value>(), R"(query; can be specified multiple times (--query "SELECT 1" --query "SELECT 2"...))") + ("query,q", po::value>()->multitoken(), R"(query; can be specified multiple times (--query "SELECT 1" --query "SELECT 2"...))") ("queries-file", po::value>()->multitoken(), "file path with queries to execute; multiple files can be specified (--queries-file file1 file2...)") ("multiquery,n", "If specified, multiple queries separated by semicolons can be listed after --query. For convenience, it is also possible to omit --query and pass the queries directly after --multiquery.") ("multiline,m", "If specified, allow multiline queries (do not send the query on Enter)") @@ -2771,6 +2770,7 @@ void ClientBase::init(int argc, char ** argv) std::transform(external_options.begin(), external_options.end(), std::back_inserter(cmd_options), getter); } + po::variables_map options; parseAndCheckOptions(options_description, options, common_arguments); po::notify(options); diff --git a/tests/queries/0_stateless/02751_multiquery_with_argument.reference b/tests/queries/0_stateless/02751_multiquery_with_argument.reference index df9771b6bd3..843fffb476c 100644 --- a/tests/queries/0_stateless/02751_multiquery_with_argument.reference +++ b/tests/queries/0_stateless/02751_multiquery_with_argument.reference @@ -18,9 +18,6 @@ Bad arguments Bad arguments Bad arguments BAD_ARGUMENTS -Bad arguments BAD_ARGUMENTS Bad arguments Bad arguments -Bad arguments -Bad arguments diff --git a/tests/queries/0_stateless/02751_multiquery_with_argument.sh b/tests/queries/0_stateless/02751_multiquery_with_argument.sh index ce53ede3331..d742cc0ad90 100755 --- a/tests/queries/0_stateless/02751_multiquery_with_argument.sh +++ b/tests/queries/0_stateless/02751_multiquery_with_argument.sh @@ -30,9 +30,6 @@ $CLICKHOUSE_LOCAL -n --multiquery "SELECT 307; SELECT 308;" 2>&1 | grep -o 'Bad $CLICKHOUSE_LOCAL --multiquery "SELECT 309; SELECT 310;" --multiquery 2>&1 | grep -o 'Bad arguments' $CLICKHOUSE_LOCAL --multiquery "SELECT 311;" --multiquery "SELECT 312;" 2>&1 | grep -o 'Bad arguments' $CLICKHOUSE_LOCAL --multiquery "SELECT 313;" -n "SELECT 314;" 2>&1 | grep -o 'BAD_ARGUMENTS' -$CLICKHOUSE_LOCAL --multiquery "SELECT 315;" --query "SELECT 316;" 2>&1 | grep -o 'Bad arguments' $CLICKHOUSE_LOCAL -n "SELECT 320" --query "SELECT 317;" 2>&1 | grep -o 'BAD_ARGUMENTS' -$CLICKHOUSE_LOCAL --query --multiquery --multiquery "SELECT 318;" 2>&1 | grep -o 'Bad arguments' -$CLICKHOUSE_LOCAL --query --multiquery "SELECT 319;" 2>&1 | grep -o 'Bad arguments' $CLICKHOUSE_LOCAL --query -n "SELECT 400;" 2>&1 | grep -o 'Bad arguments' -$CLICKHOUSE_LOCAL --query -n --multiquery "SELECT 401;" 2>&1 | grep -o 'Bad arguments' \ No newline at end of file +$CLICKHOUSE_LOCAL --query -n --multiquery "SELECT 401;" 2>&1 | grep -o 'Bad arguments' From d372776de62239ba6919e355e5d0baebf359f347 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Wed, 6 Sep 2023 19:46:52 +0000 Subject: [PATCH 5/6] Fix more tests --- ...d_optimize_skip_select_on_unused_shards.reference | 12 ++++++------ ...p_select_on_unused_shards_with_prewhere.reference | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards.reference b/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards.reference index aa509893230..add8c239ade 100644 --- a/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards.reference +++ b/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards.reference @@ -1,7 +1,7 @@ OK OK 1 -FAIL +OK 0 4 2 @@ -9,8 +9,8 @@ FAIL 1 1 4 -FAIL -FAIL -FAIL -FAIL -FAIL +OK +OK +OK +OK +OK diff --git a/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards_with_prewhere.reference b/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards_with_prewhere.reference index 611f0fd2585..4c66ccfd2a2 100644 --- a/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards_with_prewhere.reference +++ b/tests/queries/0_stateless/00754_distributed_optimize_skip_select_on_unused_shards_with_prewhere.reference @@ -1,15 +1,15 @@ OK OK 1 -FAIL +OK 0 1 4 4 2 4 -FAIL -FAIL -FAIL -FAIL -FAIL +OK +OK +OK +OK +OK From fc105aa442f6ece56dfaeb5d6541c793bde412f1 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Thu, 7 Sep 2023 10:59:19 +0000 Subject: [PATCH 6/6] Fix another test --- tests/queries/0_stateless/01339_client_unrecognized_option.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/01339_client_unrecognized_option.sh b/tests/queries/0_stateless/01339_client_unrecognized_option.sh index b3488d010c2..0cfb705185e 100755 --- a/tests/queries/0_stateless/01339_client_unrecognized_option.sh +++ b/tests/queries/0_stateless/01339_client_unrecognized_option.sh @@ -11,7 +11,7 @@ $CLICKHOUSE_CLIENT -xyzgarbage 2>&1 | grep -q "UNRECOGNIZED_ARGUMENTS" && echo ' $CLICKHOUSE_CLIENT --xyzgarbage 2>&1 | grep -q "UNRECOGNIZED_ARGUMENTS" && echo 'OK' || echo 'FAIL' -cat /etc/passwd | sed 's/:/\t/g' | $CLICKHOUSE_CLIENT --query="SELECT shell, count() AS c FROM passwd GROUP BY shell ORDER BY c DESC" --external --file=- --name=passwd --structure='login String, unused String, uid UInt16, gid UInt16, comment String, home String, shell String' xyzgarbage 2>&1 | grep -q "BAD_ARGUMENTS" && echo 'OK' || echo 'FAIL' +cat /etc/passwd | sed 's/:/\t/g' | $CLICKHOUSE_CLIENT --query="SELECT shell, count() AS c FROM passwd GROUP BY shell ORDER BY c DESC" --external --file=- --name=passwd --structure='login String, unused String, uid UInt16, gid UInt16, comment String, home String, shell String' xyzgarbage 2>&1 | grep -q "SYNTAX_ERROR" && echo 'OK' || echo 'FAIL' cat /etc/passwd | sed 's/:/\t/g' | $CLICKHOUSE_CLIENT --query="SELECT shell, count() AS c FROM passwd GROUP BY shell ORDER BY c DESC" --external -xyzgarbage --file=- --name=passwd --structure='login String, unused String, uid UInt16, gid UInt16, comment String, home String, shell String' 2>&1 | grep -q "Bad arguments" && echo 'OK' || echo 'FAIL'