diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 9e90596b4f8..217684830d4 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -7,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -45,8 +43,6 @@ #include -#include - #include #include #include @@ -1180,7 +1176,7 @@ void Client::processConfig() pager = config().getString("pager", ""); - is_default_format = !config().has("vertical") && !config().has("format"); + is_default_format = !config().has("vertical") && !config().has("output-format") && !config().has("format"); if (is_default_format && checkIfStdoutIsRegularFile()) { is_default_format = false; @@ -1189,9 +1185,13 @@ void Client::processConfig() format = format_from_file_name ? *format_from_file_name : "TabSeparated"; } else if (config().has("vertical")) - format = config().getString("format", "Vertical"); + { + format = config().getString("output-format", config().getString("format", "Vertical")); + } else - format = config().getString("format", is_interactive ? "PrettyCompact" : "TabSeparated"); + { + format = config().getString("output-format", config().getString("format", is_interactive ? "PrettyCompact" : "TabSeparated")); + } format_max_block_size = config().getUInt64("format_max_block_size", global_context->getSettingsRef().max_block_size); diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 6f7d3681c46..e0124f03a64 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -819,7 +819,6 @@ void LocalServer::addOptions(OptionsDescription & options_description) ("file,F", po::value(), "path to file with data of the initial table (stdin if not specified)") ("input-format", po::value(), "input format of the initial table data") - ("output-format", po::value(), "default output format") ("logger.console", po::value()->implicit_value(true), "Log to console") ("logger.log", po::value(), "Log file name") diff --git a/src/Client/ClientBase.cpp b/src/Client/ClientBase.cpp index 8b13f2a4ffd..c97669760f9 100644 --- a/src/Client/ClientBase.cpp +++ b/src/Client/ClientBase.cpp @@ -2892,7 +2892,9 @@ void ClientBase::init(int argc, char ** argv) ("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") + ("format,f", po::value(), "default output format (and input format for clickhouse-local)") + ("output-format", po::value(), "default output format (this option has preference over --format)") + ("vertical,E", "vertical output format, same as --format=Vertical or FORMAT Vertical or \\G at end of command") ("highlight", po::value()->default_value(true), "enable or disable basic syntax highlight in interactive command line") @@ -2975,6 +2977,8 @@ void ClientBase::init(int argc, char ** argv) config().setBool("ignore-error", true); if (options.count("format")) config().setString("format", options["format"].as()); + if (options.count("output-format")) + config().setString("output-format", options["output-format"].as()); if (options.count("vertical")) config().setBool("vertical", true); if (options.count("stacktrace")) diff --git a/src/Planner/PlannerContext.cpp b/src/Planner/PlannerContext.cpp index f939b959ce7..c9187e6aa2a 100644 --- a/src/Planner/PlannerContext.cpp +++ b/src/Planner/PlannerContext.cpp @@ -32,6 +32,9 @@ const ColumnIdentifier & GlobalPlannerContext::createColumnIdentifier(const Name column_identifier = column.name; auto [it, inserted] = column_identifiers.emplace(column_identifier); + if (!inserted) + throw Exception(ErrorCodes::LOGICAL_ERROR, "Column identifier {} is already registered", column_identifier); + assert(inserted); return *it; diff --git a/src/Planner/PlannerJoinTree.cpp b/src/Planner/PlannerJoinTree.cpp index f039c06e50b..dddab524101 100644 --- a/src/Planner/PlannerJoinTree.cpp +++ b/src/Planner/PlannerJoinTree.cpp @@ -960,8 +960,14 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres } else { + std::shared_ptr subquery_planner_context; + if (wrap_read_columns_in_subquery) + subquery_planner_context = std::make_shared(nullptr, nullptr, FiltersForTableExpressionMap{}); + else + subquery_planner_context = planner_context->getGlobalPlannerContext(); + auto subquery_options = select_query_options.subquery(); - Planner subquery_planner(table_expression, subquery_options, planner_context->getGlobalPlannerContext()); + Planner subquery_planner(table_expression, subquery_options, subquery_planner_context); /// Propagate storage limits to subquery subquery_planner.addStorageLimits(*select_query_info.storage_limits); subquery_planner.buildQueryPlanIfNeeded(); diff --git a/tests/clickhouse-test b/tests/clickhouse-test index 0dd408a2c8c..10851d23481 100755 --- a/tests/clickhouse-test +++ b/tests/clickhouse-test @@ -1387,7 +1387,6 @@ class TestCase: self.reference_file, self.stdout_file, ], - encoding="latin-1", stdout=PIPE, universal_newlines=True, ) as diff_proc: diff --git a/tests/queries/0_stateless/03020_output_format_client.reference b/tests/queries/0_stateless/03020_output_format_client.reference new file mode 100644 index 00000000000..7738e2cffb2 --- /dev/null +++ b/tests/queries/0_stateless/03020_output_format_client.reference @@ -0,0 +1,12 @@ +| x | +|:-| +| Hello, world | +| x | +|:-| +| Hello, world | +| x | +|:-| +| Hello, world | +| x | +|:-| +| Hello, world | diff --git a/tests/queries/0_stateless/03020_output_format_client.sh b/tests/queries/0_stateless/03020_output_format_client.sh new file mode 100755 index 00000000000..b641af3e2e4 --- /dev/null +++ b/tests/queries/0_stateless/03020_output_format_client.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +# clickhouse-local has --input-format and --output-format parameters, +# and also the --format parameter which is the default for both input and output formats, but has less preference. + +# clickhouse-client does not have the --input-format parameter. +# However, it accepts both --format and --output-format for convenience. + +${CLICKHOUSE_LOCAL} --output-format Markdown --query "SELECT 'Hello, world' AS x" +${CLICKHOUSE_CLIENT} --output-format Markdown --query "SELECT 'Hello, world' AS x" +${CLICKHOUSE_LOCAL} --format Markdown --query "SELECT 'Hello, world' AS x" +${CLICKHOUSE_CLIENT} --format Markdown --query "SELECT 'Hello, world' AS x"