Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clickhouse-client: disallow usage of --query and --queries-file at the same time #50210

Merged
merged 4 commits into from Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions programs/client/Client.cpp
Expand Up @@ -1180,6 +1180,9 @@ void Client::processOptions(const OptionsDescription & options_description,

void Client::processConfig()
{
if (config().has("query") && 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:
/// - -q (--query) command line option is present.
/// The value of the option is used as the text of query (or of multiple queries).
Expand Down
6 changes: 3 additions & 3 deletions programs/local/LocalServer.cpp
Expand Up @@ -516,12 +516,12 @@ void LocalServer::updateLoggerLevel(const String & logs_level)

void LocalServer::processConfig()
{
if (config().has("query") && 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"));
if (is_interactive && !delayed_interactive)
{
if (config().has("query") && config().has("queries-file"))
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Specify either `query` or `queries-file` option");

if (config().has("multiquery"))
is_multiquery = true;
}
Expand Down
Expand Up @@ -4,3 +4,7 @@
3
1 2
3 4
BAD_ARGUMENTS
BAD_ARGUMENTS
BAD_ARGUMENTS
BAD_ARGUMENTS
Expand Up @@ -5,20 +5,29 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh

echo "SELECT 1;" > 01523_client_local_queries_file_parameter_tmp.sql
$CLICKHOUSE_CLIENT --queries-file=01523_client_local_queries_file_parameter_tmp.sql 2>&1
## Use process ID ($$) for uniqueness of file name
TEMP_SQL_FILE_NAME=$"01523_client_local_queries_file_parameter_tmp_$$.sql"
echo "SELECT 1;" > "$TEMP_SQL_FILE_NAME"
$CLICKHOUSE_CLIENT --queries-file="$TEMP_SQL_FILE_NAME" 2>&1

echo "CREATE TABLE 01523_test(value Int32) ENGINE=Log;
INSERT INTO 01523_test
VALUES (1), (2), (3);
SELECT * FROM 01523_test;
DROP TABLE 01523_test;" > 01523_client_local_queries_file_parameter_tmp.sql
$CLICKHOUSE_CLIENT --queries-file=01523_client_local_queries_file_parameter_tmp.sql 2>&1
DROP TABLE 01523_test;" > "$TEMP_SQL_FILE_NAME"
$CLICKHOUSE_CLIENT --queries-file="$TEMP_SQL_FILE_NAME" 2>&1

echo "CREATE TABLE 01523_test (a Int64, b Int64) ENGINE = File(CSV, stdin);
SELECT a, b FROM 01523_test;
DROP TABLE 01523_test;" > 01523_client_local_queries_file_parameter_tmp.sql
DROP TABLE 01523_test;" > "$TEMP_SQL_FILE_NAME"

echo -e "1,2\n3,4" | $CLICKHOUSE_LOCAL --queries-file=01523_client_local_queries_file_parameter_tmp.sql 2>&1
echo -e "1,2\n3,4" | $CLICKHOUSE_LOCAL --queries-file="$TEMP_SQL_FILE_NAME" 2>&1

rm 01523_client_local_queries_file_parameter_tmp.sql
# Simultaneously passing --queries-file + --query is prohibited.
echo "SELECT 1;" > "$TEMP_SQL_FILE_NAME"
$CLICKHOUSE_LOCAL --queries-file="$TEMP_SQL_FILE_NAME" -q "SELECT 1;" 2>&1 | grep -o 'BAD_ARGUMENTS'
$CLICKHOUSE_CLIENT --queries-file="$TEMP_SQL_FILE_NAME" -q "SELECT 2;" 2>&1 | grep -o 'BAD_ARGUMENTS'
$CLICKHOUSE_LOCAL --queries-file="$TEMP_SQL_FILE_NAME" --query "SELECT 3;" 2>&1 | grep -o 'BAD_ARGUMENTS'
$CLICKHOUSE_CLIENT --queries-file="$TEMP_SQL_FILE_NAME" --query "SELECT 4;" 2>&1 | grep -o 'BAD_ARGUMENTS'

rm "$TEMP_SQL_FILE_NAME"
Expand Up @@ -8,6 +8,8 @@ Empty query
BAD_ARGUMENTS
BAD_ARGUMENTS
BAD_ARGUMENTS
BAD_ARGUMENTS
BAD_ARGUMENTS
Bad arguments
Bad arguments
Bad arguments
Expand Down
4 changes: 4 additions & 0 deletions tests/queries/0_stateless/02751_multiquery_with_argument.sh
Expand Up @@ -13,6 +13,10 @@ $CLICKHOUSE_LOCAL --multiquery "SELECT 200; S" 2>&1 | grep -o 'Syntax error'
$CLICKHOUSE_LOCAL --multiquery "; SELECT 201;" 2>&1 | grep -o 'Empty query'
$CLICKHOUSE_LOCAL --multiquery "; S; SELECT 202" 2>&1 | grep -o 'Empty query'

# Simultaneously passing --queries-file + --query (multiquery) is prohibited.
$CLICKHOUSE_LOCAL --queries-file "queries.csv" --multiquery "SELECT 250;" 2>&1 | grep -o 'BAD_ARGUMENTS'
$CLICKHOUSE_CLIENT --queries-file "queries.csv" --multiquery "SELECT 251;" 2>&1 | grep -o 'BAD_ARGUMENTS'

# Error expectation cases.
# -n <SQL> is prohibited
$CLICKHOUSE_LOCAL -n "SELECT 301" 2>&1 | grep -o 'BAD_ARGUMENTS'
Expand Down