From 8b438bcd3c7ff07127816aaa61f775718dec2204 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 15 May 2021 12:11:13 +0300 Subject: [PATCH] Change formatting of subqueries (make it more human friendly) Fix trailing whitespaces in FROM/IN clause with subqueries in multiline mode, and also changes the output of the queries slightly in a more human friendly way. Before: $ clickhouse-format <<<'select * from system.one, (select * from system.one)' SELECT * FROM system.one , ( SELECT * FROM system.one ) After: $ clickhouse-format <<<'select * from system.one, (select * from system.one)' SELECT * FROM system.one, ( SELECT * FROM system.one ) v2: Fix subqueries formatting in a different way v3: Adjust *.reference in tests v4: Fix modernize-loop-convert in ASTTablesInSelectQuery --- src/Parsers/ASTSelectQuery.cpp | 2 +- src/Parsers/ASTSelectWithUnionQuery.cpp | 10 +- src/Parsers/ASTSubquery.cpp | 7 +- src/Parsers/ASTTablesInSelectQuery.cpp | 24 ++-- src/Parsers/ASTWithElement.cpp | 5 +- ...0077_set_keys_fit_128_bits_many_blocks.sql | 2 +- ...316_rounding_functions_and_empty_block.sql | 2 +- ...ll_subquery_aggregation_column_removal.sql | 24 ++-- .../00597_push_down_predicate.reference | 98 +++++++-------- .../00599_create_view_with_subquery.reference | 2 +- .../queries/0_stateless/00618_nullable_in.sql | 2 +- .../00743_limit_by_not_found_column.sql | 2 +- ...51_default_databasename_for_view.reference | 9 +- .../00808_not_optimize_predicate.reference | 2 +- .../00849_multiple_comma_join_2.reference | 40 +++--- ...0957_format_with_clashed_aliases.reference | 2 +- .../01029_early_constant_folding.reference | 3 +- .../01054_cache_dictionary_overflow_cell.sql | 2 +- .../01056_predicate_optimizer_bugs.reference | 28 ++--- tests/queries/0_stateless/01067_join_null.sql | 6 +- ...76_predicate_optimizer_with_view.reference | 8 +- ..._expressions_in_engine_arguments.reference | 2 +- .../01245_limit_infinite_sources.sql | 2 +- ...ithmetic_operations_in_aggr_func.reference | 96 +++++++-------- ..._duplicate_order_by_and_distinct.reference | 16 +-- ...egate_functions_of_group_by_keys.reference | 4 +- ..._redundant_functions_in_order_by.reference | 16 +-- .../01372_wrong_order_by_removal.reference | 2 +- .../01390_remove_injective_in_uniq.reference | 28 ++--- .../0_stateless/01412_row_from_totals.sql | 2 +- ...dicate_when_contains_with_clause.reference | 2 +- ..._duplicate_distinct_optimization.reference | 36 +++--- ...5_subqueries_in_with_statement_4.reference | 5 +- ...with_global_and_with_propagation.reference | 9 +- .../0_stateless/01532_having_with_totals.sql | 4 +- .../01532_min_max_with_modifiers.sql | 2 +- .../01559_aggregate_null_for_empty_fix.sql | 16 +-- ...60_DateTime_and_DateTime64_comparision.sql | 2 +- ...0_monotonicity_check_multiple_args_bug.sql | 4 +- ...ministic_function_with_predicate.reference | 4 +- .../01593_functions_in_order_by.reference | 2 +- .../01593_functions_in_order_by.sql | 2 +- .../0_stateless/01635_nullable_fuzz.sql | 2 +- .../0_stateless/01636_nullable_fuzz2.sql | 2 +- .../01650_expressions_merge_bug.sql | 2 +- .../0_stateless/01670_neighbor_lc_bug.sql | 2 +- ...01732_explain_syntax_union_query.reference | 16 +-- .../01732_explain_syntax_union_query.sql | 14 +-- ...1754_clickhouse_format_backslash.reference | 2 +- .../01798_uniq_theta_sketch.reference | 24 ++-- ...select_from_trailing_whitespaces.reference | 114 ++++++++++++++++++ .../01874_select_from_trailing_whitespaces.sh | 30 +++++ .../1_stateful/00031_array_enumerate_uniq.sql | 2 +- .../1_stateful/00063_loyalty_joins.sql | 8 +- 54 files changed, 453 insertions(+), 301 deletions(-) create mode 100644 tests/queries/0_stateless/01874_select_from_trailing_whitespaces.reference create mode 100755 tests/queries/0_stateless/01874_select_from_trailing_whitespaces.sh diff --git a/src/Parsers/ASTSelectQuery.cpp b/src/Parsers/ASTSelectQuery.cpp index 4715c7f201b..b5cfa17f035 100644 --- a/src/Parsers/ASTSelectQuery.cpp +++ b/src/Parsers/ASTSelectQuery.cpp @@ -95,7 +95,7 @@ void ASTSelectQuery::formatImpl(const FormatSettings & s, FormatState & state, F if (tables()) { - s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "FROM " << (s.hilite ? hilite_none : ""); + s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "FROM" << (s.hilite ? hilite_none : ""); tables()->formatImpl(s, state, frame); } diff --git a/src/Parsers/ASTSelectWithUnionQuery.cpp b/src/Parsers/ASTSelectWithUnionQuery.cpp index 6a990a3d154..fa7359574f8 100644 --- a/src/Parsers/ASTSelectWithUnionQuery.cpp +++ b/src/Parsers/ASTSelectWithUnionQuery.cpp @@ -35,24 +35,24 @@ void ASTSelectWithUnionQuery::formatQueryImpl(const FormatSettings & settings, F if (mode == Mode::Unspecified) return ""; else if (mode == Mode::ALL) - return "ALL"; + return " ALL"; else - return "DISTINCT"; + return " DISTINCT"; }; for (ASTs::const_iterator it = list_of_selects->children.begin(); it != list_of_selects->children.end(); ++it) { if (it != list_of_selects->children.begin()) - settings.ostr << settings.nl_or_ws << indent_str << (settings.hilite ? hilite_keyword : "") << "UNION " + settings.ostr << settings.nl_or_ws << indent_str << (settings.hilite ? hilite_keyword : "") << "UNION" << mode_to_str((is_normalized) ? union_mode : list_of_modes[it - list_of_selects->children.begin() - 1]) << (settings.hilite ? hilite_none : ""); if (auto * node = (*it)->as()) { + settings.ostr << settings.nl_or_ws << indent_str; + if (node->list_of_selects->children.size() == 1) { - if (it != list_of_selects->children.begin()) - settings.ostr << settings.nl_or_ws; (node->list_of_selects->children.at(0))->formatImpl(settings, state, frame); } else diff --git a/src/Parsers/ASTSubquery.cpp b/src/Parsers/ASTSubquery.cpp index 142072050a6..58f334376e6 100644 --- a/src/Parsers/ASTSubquery.cpp +++ b/src/Parsers/ASTSubquery.cpp @@ -29,6 +29,11 @@ void ASTSubquery::appendColumnNameImpl(WriteBuffer & ostr) const void ASTSubquery::formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const { + /// NOTE: due to trickery of filling cte_name (in interpreters) it is hard + /// to print it w/o newline (for !oneline case), since if nl_or_ws + /// prepended here, then formatting will be incorrect with alias: + /// + /// (select 1 in ((select 1) as sub)) if (!cte_name.empty()) { settings.ostr << (settings.hilite ? hilite_identifier : ""); @@ -40,7 +45,7 @@ void ASTSubquery::formatImplWithoutAlias(const FormatSettings & settings, Format std::string indent_str = settings.one_line ? "" : std::string(4u * frame.indent, ' '); std::string nl_or_nothing = settings.one_line ? "" : "\n"; - settings.ostr << nl_or_nothing << indent_str << "(" << nl_or_nothing; + settings.ostr << "(" << nl_or_nothing; FormatStateStacked frame_nested = frame; frame_nested.need_parens = false; ++frame_nested.indent; diff --git a/src/Parsers/ASTTablesInSelectQuery.cpp b/src/Parsers/ASTTablesInSelectQuery.cpp index 8d131a848f7..e063b9f7125 100644 --- a/src/Parsers/ASTTablesInSelectQuery.cpp +++ b/src/Parsers/ASTTablesInSelectQuery.cpp @@ -109,14 +109,17 @@ void ASTTableExpression::formatImpl(const FormatSettings & settings, FormatState if (database_and_table_name) { + settings.ostr << " "; database_and_table_name->formatImpl(settings, state, frame); } else if (table_function) { + settings.ostr << " "; table_function->formatImpl(settings, state, frame); } else if (subquery) { + settings.ostr << settings.nl_or_ws << indent_str; subquery->formatImpl(settings, state, frame); } @@ -142,9 +145,15 @@ void ASTTableExpression::formatImpl(const FormatSettings & settings, FormatState } -void ASTTableJoin::formatImplBeforeTable(const FormatSettings & settings, FormatState &, FormatStateStacked) const +void ASTTableJoin::formatImplBeforeTable(const FormatSettings & settings, FormatState &, FormatStateStacked frame) const { settings.ostr << (settings.hilite ? hilite_keyword : ""); + std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' '); + + if (kind != Kind::Comma) + { + settings.ostr << settings.nl_or_ws << indent_str; + } switch (locality) { @@ -241,6 +250,7 @@ void ASTArrayJoin::formatImpl(const FormatSettings & settings, FormatState & sta frame.expression_list_prepend_whitespace = true; settings.ostr << (settings.hilite ? hilite_keyword : "") + << settings.nl_or_ws << (kind == Kind::Left ? "LEFT " : "") << "ARRAY JOIN" << (settings.hilite ? hilite_none : ""); settings.one_line @@ -254,10 +264,7 @@ void ASTTablesInSelectQueryElement::formatImpl(const FormatSettings & settings, if (table_expression) { if (table_join) - { table_join->as().formatImplBeforeTable(settings, state, frame); - settings.ostr << " "; - } table_expression->formatImpl(settings, state, frame); @@ -275,13 +282,8 @@ void ASTTablesInSelectQuery::formatImpl(const FormatSettings & settings, FormatS { std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' '); - for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it) - { - if (it != children.begin()) - settings.ostr << settings.nl_or_ws << indent_str; - - (*it)->formatImpl(settings, state, frame); - } + for (const auto & child : children) + child->formatImpl(settings, state, frame); } } diff --git a/src/Parsers/ASTWithElement.cpp b/src/Parsers/ASTWithElement.cpp index ce39086eb4a..b517509c4bc 100644 --- a/src/Parsers/ASTWithElement.cpp +++ b/src/Parsers/ASTWithElement.cpp @@ -16,8 +16,11 @@ ASTPtr ASTWithElement::clone() const void ASTWithElement::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const { + std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' '); + settings.writeIdentifier(name); - settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS " << (settings.hilite ? hilite_none : ""); + settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS" << (settings.hilite ? hilite_none : ""); + settings.ostr << settings.nl_or_ws << indent_str; dynamic_cast(*subquery).formatImplWithoutAlias(settings, state, frame); } diff --git a/tests/queries/0_stateless/00077_set_keys_fit_128_bits_many_blocks.sql b/tests/queries/0_stateless/00077_set_keys_fit_128_bits_many_blocks.sql index 02f0a6648a8..fe6a0cefd31 100644 --- a/tests/queries/0_stateless/00077_set_keys_fit_128_bits_many_blocks.sql +++ b/tests/queries/0_stateless/00077_set_keys_fit_128_bits_many_blocks.sql @@ -1,6 +1,6 @@ SET max_block_size = 1000; -SELECT number FROM +SELECT number FROM ( SELECT * FROM system.numbers LIMIT 10000 ) diff --git a/tests/queries/0_stateless/00316_rounding_functions_and_empty_block.sql b/tests/queries/0_stateless/00316_rounding_functions_and_empty_block.sql index 9f91cd713ae..08c30324da4 100644 --- a/tests/queries/0_stateless/00316_rounding_functions_and_empty_block.sql +++ b/tests/queries/0_stateless/00316_rounding_functions_and_empty_block.sql @@ -2,7 +2,7 @@ SET any_join_distinct_right_table_keys = 1; SELECT floor((ReferrerTimestamp - InstallTimestamp) / 86400) AS DaysSinceInstallations -FROM +FROM ( SELECT 6534090703218709881 AS DeviceIDHash, 1458586663 AS InstallTimestamp UNION ALL SELECT 2697418689476658272, 1458561552 diff --git a/tests/queries/0_stateless/00585_union_all_subquery_aggregation_column_removal.sql b/tests/queries/0_stateless/00585_union_all_subquery_aggregation_column_removal.sql index bf5d2251470..49975daaa7e 100644 --- a/tests/queries/0_stateless/00585_union_all_subquery_aggregation_column_removal.sql +++ b/tests/queries/0_stateless/00585_union_all_subquery_aggregation_column_removal.sql @@ -11,7 +11,7 @@ INSERT INTO transactions VALUES ('facebook.com'), ('yandex.ru'), ('baidu.com'); SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -36,7 +36,7 @@ FORMAT JSONEachRow; SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -63,7 +63,7 @@ SELECT DISTINCT * FROM SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -88,7 +88,7 @@ UNION ALL SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -116,7 +116,7 @@ SELECT sum(total_count) AS total, sum(facebookHits) AS facebook, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -142,7 +142,7 @@ SELECT sum(total_count) AS total, max(facebookHits) AS facebook, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -170,7 +170,7 @@ SELECT * FROM SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -195,7 +195,7 @@ ALL FULL OUTER JOIN SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -224,7 +224,7 @@ SELECT total FROM SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -249,7 +249,7 @@ ALL FULL OUTER JOIN SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -278,7 +278,7 @@ SELECT domain FROM SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, @@ -303,7 +303,7 @@ ALL FULL OUTER JOIN SELECT sum(total_count) AS total, domain -FROM +FROM ( SELECT COUNT(*) AS total_count, diff --git a/tests/queries/0_stateless/00597_push_down_predicate.reference b/tests/queries/0_stateless/00597_push_down_predicate.reference index 59313c35b81..bd7d3cd81d4 100644 --- a/tests/queries/0_stateless/00597_push_down_predicate.reference +++ b/tests/queries/0_stateless/00597_push_down_predicate.reference @@ -5,7 +5,7 @@ 2000-01-01 1 test string 1 1 -------Forbid push down------- SELECT count() -FROM +FROM ( SELECT [number] AS a, @@ -21,11 +21,11 @@ WHERE NOT ignore(a + b) SELECT a, b -FROM +FROM ( SELECT 1 AS a ) -ANY LEFT JOIN +ANY LEFT JOIN ( SELECT 1 AS a, @@ -35,13 +35,13 @@ WHERE b = 0 SELECT a, b -FROM +FROM ( SELECT 1 AS a, 1 AS b ) -ANY RIGHT JOIN +ANY RIGHT JOIN ( SELECT 1 AS a ) USING (a) @@ -49,11 +49,11 @@ WHERE b = 0 SELECT a, b -FROM +FROM ( SELECT 1 AS a ) -ANY FULL OUTER JOIN +ANY FULL OUTER JOIN ( SELECT 1 AS a, @@ -63,26 +63,26 @@ WHERE b = 0 SELECT a, b -FROM +FROM ( SELECT 1 AS a, 1 AS b ) -ANY FULL OUTER JOIN +ANY FULL OUTER JOIN ( SELECT 1 AS a ) USING (a) WHERE b = 0 -------Need push down------- SELECT toString(value) AS value -FROM +FROM ( SELECT 1 AS value ) 1 SELECT id -FROM +FROM ( SELECT 1 AS id UNION ALL @@ -92,7 +92,7 @@ FROM WHERE id = 1 1 SELECT id -FROM +FROM ( SELECT arrayJoin([1, 2, 3]) AS id WHERE id = 1 @@ -100,7 +100,7 @@ FROM WHERE id = 1 1 SELECT id -FROM +FROM ( SELECT arrayJoin([1, 2, 3]) AS id WHERE id = 1 @@ -110,7 +110,7 @@ WHERE id = 1 SELECT id, subquery -FROM +FROM ( SELECT 1 AS id, @@ -122,7 +122,7 @@ WHERE subquery = 1 SELECT a, b -FROM +FROM ( SELECT toUInt64(sum(id) AS b) AS a, @@ -137,7 +137,7 @@ SELECT id, name, value -FROM +FROM ( SELECT date, @@ -156,7 +156,7 @@ WHERE id = 1 SELECT a, b -FROM +FROM ( SELECT toUInt64(sum(id) AS b) AS a, @@ -171,7 +171,7 @@ SELECT id, name, value -FROM +FROM ( SELECT date, @@ -188,14 +188,14 @@ SELECT id, name, value -FROM +FROM ( SELECT date, id, name, value - FROM + FROM ( SELECT date, @@ -214,14 +214,14 @@ SELECT id, name, value -FROM +FROM ( SELECT date, id, name, value - FROM + FROM ( SELECT date, @@ -240,7 +240,7 @@ SELECT id, name, value -FROM +FROM ( SELECT date, @@ -257,14 +257,14 @@ SELECT id, name, value -FROM +FROM ( SELECT date, id, name, value - FROM + FROM ( SELECT date, @@ -283,7 +283,7 @@ SELECT id, name, value -FROM +FROM ( SELECT date, @@ -300,14 +300,14 @@ SELECT id, name, value -FROM +FROM ( SELECT date, id, name, value - FROM + FROM ( SELECT date, @@ -325,7 +325,7 @@ SELECT id, date, value -FROM +FROM ( SELECT id, @@ -344,7 +344,7 @@ SELECT id, name, value -FROM +FROM ( SELECT date, @@ -373,7 +373,7 @@ SELECT date, name, value -FROM +FROM ( SELECT date, @@ -383,7 +383,7 @@ FROM FROM test_00597 WHERE id = 1 ) -ANY LEFT JOIN +ANY LEFT JOIN ( SELECT id FROM test_00597 @@ -395,11 +395,11 @@ SELECT date, name, value -FROM +FROM ( SELECT toInt8(1) AS id ) -ANY LEFT JOIN +ANY LEFT JOIN ( SELECT date, @@ -411,7 +411,7 @@ ANY LEFT JOIN WHERE value = 1 1 2000-01-01 test string 1 1 SELECT value -FROM +FROM ( SELECT toInt8(1) AS id ) @@ -423,7 +423,7 @@ SELECT id, name, value -FROM +FROM ( SELECT date, @@ -433,7 +433,7 @@ FROM date, name, value - FROM + FROM ( SELECT date, @@ -443,7 +443,7 @@ FROM FROM test_00597 WHERE id = 1 ) - ANY LEFT JOIN + ANY LEFT JOIN ( SELECT id FROM test_00597 @@ -460,7 +460,7 @@ SELECT b.date, b.name, b.value -FROM +FROM ( SELECT date, @@ -469,7 +469,7 @@ FROM value FROM test_00597 ) -ANY LEFT JOIN +ANY LEFT JOIN ( SELECT date, @@ -485,7 +485,7 @@ SELECT date, name, value -FROM +FROM ( SELECT toInt8(1) AS id, @@ -493,7 +493,7 @@ FROM FROM system.numbers LIMIT 1 ) -ANY LEFT JOIN +ANY LEFT JOIN ( SELECT date, @@ -513,7 +513,7 @@ SELECT `b.id`, `b.name`, `b.value` -FROM +FROM ( SELECT date, @@ -524,7 +524,7 @@ FROM b.id, b.name, b.value - FROM + FROM ( SELECT date, @@ -534,7 +534,7 @@ FROM FROM test_00597 WHERE id = 1 ) AS a - ANY LEFT JOIN + ANY LEFT JOIN ( SELECT date, @@ -555,7 +555,7 @@ SELECT r.date, r.name, r.value -FROM +FROM ( SELECT date, @@ -564,14 +564,14 @@ FROM value FROM test_00597 ) -SEMI LEFT JOIN +SEMI LEFT JOIN ( SELECT date, id, name, value - FROM + FROM ( SELECT date, @@ -586,7 +586,7 @@ SEMI LEFT JOIN WHERE r.id = 1 2000-01-01 1 test string 1 1 2000-01-01 test string 1 1 SELECT value + t1.value AS expr -FROM +FROM ( SELECT value, diff --git a/tests/queries/0_stateless/00599_create_view_with_subquery.reference b/tests/queries/0_stateless/00599_create_view_with_subquery.reference index d83d2837a18..0458f650fd0 100644 --- a/tests/queries/0_stateless/00599_create_view_with_subquery.reference +++ b/tests/queries/0_stateless/00599_create_view_with_subquery.reference @@ -1 +1 @@ -CREATE VIEW default.test_view_00599\n(\n `id` UInt64\n) AS\nSELECT *\nFROM default.test_00599\nWHERE id = \n(\n SELECT 1\n) +CREATE VIEW default.test_view_00599\n(\n `id` UInt64\n) AS\nSELECT *\nFROM default.test_00599\nWHERE id = (\n SELECT 1\n) diff --git a/tests/queries/0_stateless/00618_nullable_in.sql b/tests/queries/0_stateless/00618_nullable_in.sql index 72e166dc0f5..f039f1fb9d5 100644 --- a/tests/queries/0_stateless/00618_nullable_in.sql +++ b/tests/queries/0_stateless/00618_nullable_in.sql @@ -5,7 +5,7 @@ SELECT uniqExact(x) AS u, uniqExactIf(x, name = 'a') AS ue, uniqExactIf(x, name IN ('a', 'b')) AS ui -FROM +FROM ( SELECT toNullable('a') AS name, diff --git a/tests/queries/0_stateless/00743_limit_by_not_found_column.sql b/tests/queries/0_stateless/00743_limit_by_not_found_column.sql index d20b3b0209e..831d67f624b 100644 --- a/tests/queries/0_stateless/00743_limit_by_not_found_column.sql +++ b/tests/queries/0_stateless/00743_limit_by_not_found_column.sql @@ -22,7 +22,7 @@ DROP TABLE installation_stats; CREATE TEMPORARY TABLE Accounts (AccountID UInt64, Currency String); SELECT AccountID -FROM +FROM ( SELECT AccountID, diff --git a/tests/queries/0_stateless/00751_default_databasename_for_view.reference b/tests/queries/0_stateless/00751_default_databasename_for_view.reference index 76d5cee02e2..b3f1875ae91 100644 --- a/tests/queries/0_stateless/00751_default_databasename_for_view.reference +++ b/tests/queries/0_stateless/00751_default_databasename_for_view.reference @@ -12,14 +12,11 @@ SELECT platform, app FROM test_00751.t_00751 -WHERE (app = -( +WHERE (app = ( SELECT min(app) FROM test_00751.u_00751 -)) AND (platform = -( - SELECT - ( +)) AND (platform = ( + SELECT ( SELECT min(platform) FROM test_00751.v_00751 ) diff --git a/tests/queries/0_stateless/00808_not_optimize_predicate.reference b/tests/queries/0_stateless/00808_not_optimize_predicate.reference index d8ab9425aab..647c6d91890 100644 --- a/tests/queries/0_stateless/00808_not_optimize_predicate.reference +++ b/tests/queries/0_stateless/00808_not_optimize_predicate.reference @@ -18,7 +18,7 @@ SELECT n, `finalizeAggregation(s)` -FROM +FROM ( SELECT n, diff --git a/tests/queries/0_stateless/00849_multiple_comma_join_2.reference b/tests/queries/0_stateless/00849_multiple_comma_join_2.reference index fc39ef13935..5709db44eb1 100644 --- a/tests/queries/0_stateless/00849_multiple_comma_join_2.reference +++ b/tests/queries/0_stateless/00849_multiple_comma_join_2.reference @@ -10,7 +10,7 @@ FROM t1 ALL INNER JOIN t2 ON b = t2.b WHERE b = t2.b SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT a AS `--t1.a`, @@ -21,7 +21,7 @@ FROM ALL INNER JOIN t3 ON `--t1.a` = a WHERE (`--t1.a` = `--t2.a`) AND (`--t1.a` = a) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT b AS `--t1.b`, @@ -33,13 +33,13 @@ FROM ALL INNER JOIN t3 ON `--t1.b` = b WHERE (`--t1.b` = `--t2.b`) AND (`--t1.b` = b) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.a`, `--t2.a`, a AS `--t3.a` - FROM + FROM ( SELECT a AS `--t1.a`, @@ -52,14 +52,14 @@ FROM ALL INNER JOIN t4 ON `--t1.a` = a WHERE (`--t1.a` = `--t2.a`) AND (`--t1.a` = `--t3.a`) AND (`--t1.a` = a) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.b`, `--t1.a`, `--t2.b`, b AS `--t3.b` - FROM + FROM ( SELECT b AS `--t1.b`, @@ -73,13 +73,13 @@ FROM ALL INNER JOIN t4 ON `--t1.b` = b WHERE (`--t1.b` = `--t2.b`) AND (`--t1.b` = `--t3.b`) AND (`--t1.b` = b) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.a`, `--t2.a`, a AS `--t3.a` - FROM + FROM ( SELECT a AS `--t1.a`, @@ -92,13 +92,13 @@ FROM ALL INNER JOIN t4 ON `--t2.a` = a WHERE (`--t2.a` = `--t1.a`) AND (`--t2.a` = `--t3.a`) AND (`--t2.a` = a) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.a`, `--t2.a`, a AS `--t3.a` - FROM + FROM ( SELECT a AS `--t1.a`, @@ -111,13 +111,13 @@ FROM ALL INNER JOIN t4 ON `--t3.a` = a WHERE (`--t3.a` = `--t1.a`) AND (`--t3.a` = `--t2.a`) AND (`--t3.a` = a) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.a`, `--t2.a`, a AS `--t3.a` - FROM + FROM ( SELECT a AS `--t1.a`, @@ -130,13 +130,13 @@ FROM ALL INNER JOIN t4 ON (a = `--t1.a`) AND (a = `--t2.a`) AND (a = `--t3.a`) WHERE (a = `--t1.a`) AND (a = `--t2.a`) AND (a = `--t3.a`) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.a`, `--t2.a`, a AS `--t3.a` - FROM + FROM ( SELECT a AS `--t1.a`, @@ -149,10 +149,10 @@ FROM ALL INNER JOIN t4 ON `--t3.a` = a WHERE (`--t1.a` = `--t2.a`) AND (`--t2.a` = `--t3.a`) AND (`--t3.a` = a) SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.a` - FROM + FROM ( SELECT a AS `--t1.a` FROM t1 @@ -162,10 +162,10 @@ FROM ) AS `--.s` CROSS JOIN t4 SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT `--t1.a` - FROM + FROM ( SELECT a AS `--t1.a` FROM t1 @@ -175,7 +175,7 @@ FROM ) AS `--.s` CROSS JOIN t4 SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT a AS `--t1.a` FROM t1 @@ -183,7 +183,7 @@ FROM ) AS `--.s` CROSS JOIN t3 SELECT `--t1.a` AS `t1.a` -FROM +FROM ( SELECT a AS `--t1.a`, diff --git a/tests/queries/0_stateless/00957_format_with_clashed_aliases.reference b/tests/queries/0_stateless/00957_format_with_clashed_aliases.reference index d6e53c8b48b..cffcb8482ad 100644 --- a/tests/queries/0_stateless/00957_format_with_clashed_aliases.reference +++ b/tests/queries/0_stateless/00957_format_with_clashed_aliases.reference @@ -1,7 +1,7 @@ SELECT 1 AS x, x.y -FROM +FROM ( SELECT 'Hello, world' AS y ) AS x diff --git a/tests/queries/0_stateless/01029_early_constant_folding.reference b/tests/queries/0_stateless/01029_early_constant_folding.reference index 8a2d7e6c61a..6063e08afe0 100644 --- a/tests/queries/0_stateless/01029_early_constant_folding.reference +++ b/tests/queries/0_stateless/01029_early_constant_folding.reference @@ -4,8 +4,7 @@ SELECT 1 SELECT 1 WHERE (1 IN (0, 2)) AND (2 = (identity(CAST(2, \'UInt8\')) AS subquery)) SELECT 1 -WHERE 1 IN ( -( +WHERE 1 IN (( SELECT arrayJoin([1, 2, 3]) ) AS subquery) SELECT 1 diff --git a/tests/queries/0_stateless/01054_cache_dictionary_overflow_cell.sql b/tests/queries/0_stateless/01054_cache_dictionary_overflow_cell.sql index b040a0e7a50..d8d1d61be63 100644 --- a/tests/queries/0_stateless/01054_cache_dictionary_overflow_cell.sql +++ b/tests/queries/0_stateless/01054_cache_dictionary_overflow_cell.sql @@ -48,7 +48,7 @@ dictGet('one_cell_cache_ints_overflow', 'i8', toUInt64(19)), dictGet('one_cell_cache_ints_overflow', 'i8', toUInt64(20)); SELECT arrayMap(x -> dictGet('one_cell_cache_ints_overflow', 'i8', toUInt64(x)), array) -FROM +FROM ( SELECT [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] AS array ); diff --git a/tests/queries/0_stateless/01056_predicate_optimizer_bugs.reference b/tests/queries/0_stateless/01056_predicate_optimizer_bugs.reference index 4227af86be7..7df4dc7ead5 100644 --- a/tests/queries/0_stateless/01056_predicate_optimizer_bugs.reference +++ b/tests/queries/0_stateless/01056_predicate_optimizer_bugs.reference @@ -3,14 +3,14 @@ SELECT v, d, i -FROM +FROM ( SELECT t.1 AS k, t.2 AS v, runningDifference(v) AS d, runningDifference(cityHash64(t.1)) AS i - FROM + FROM ( SELECT arrayJoin([(\'a\', 1), (\'a\', 2), (\'a\', 3), (\'b\', 11), (\'b\', 13), (\'b\', 15)]) AS t ) @@ -26,14 +26,14 @@ SELECT co2, co3, num -FROM +FROM ( SELECT co, co2, co3, count() AS num - FROM + FROM ( SELECT 1 AS co, @@ -51,13 +51,13 @@ WHERE (co != 0) AND (co2 != 2) 1 0 3 1 1 0 0 1 SELECT alias AS name -FROM +FROM ( SELECT name AS alias FROM system.settings WHERE alias = \'enable_optimize_predicate_expression\' ) -ANY INNER JOIN +ANY INNER JOIN ( SELECT name FROM system.settings @@ -66,17 +66,17 @@ WHERE name = \'enable_optimize_predicate_expression\' enable_optimize_predicate_expression 1 val11 val21 val31 SELECT ccc -FROM +FROM ( SELECT 1 AS ccc WHERE 0 UNION ALL SELECT ccc - FROM + FROM ( SELECT 2 AS ccc ) - ANY INNER JOIN + ANY INNER JOIN ( SELECT 2 AS ccc ) USING (ccc) @@ -91,7 +91,7 @@ SELECT b.ts, b.id, id_c -FROM +FROM ( SELECT ts, @@ -109,7 +109,7 @@ SELECT b.ts AS `--b.ts`, b.id AS `--b.id`, id_c AS `--b.id_c` -FROM +FROM ( SELECT ts, @@ -129,7 +129,7 @@ WHERE `--a.ts` <= toDateTime(\'1970-01-01 03:00:00\') 2 3 4 5 SELECT dummy -FROM +FROM ( SELECT dummy FROM system.one @@ -141,13 +141,13 @@ SELECT id, value, value_1 -FROM +FROM ( SELECT 1 AS id, 2 AS value ) -ALL INNER JOIN +ALL INNER JOIN ( SELECT 1 AS id, diff --git a/tests/queries/0_stateless/01067_join_null.sql b/tests/queries/0_stateless/01067_join_null.sql index bc888fe01ba..a00c345128c 100644 --- a/tests/queries/0_stateless/01067_join_null.sql +++ b/tests/queries/0_stateless/01067_join_null.sql @@ -1,5 +1,5 @@ SELECT id -FROM +FROM ( SELECT 1 AS id UNION ALL @@ -20,7 +20,7 @@ ORDER BY id; SELECT '---'; SELECT * -FROM +FROM ( SELECT NULL AS x ) js1 @@ -32,7 +32,7 @@ INNER JOIN SELECT '---'; SELECT * -FROM +FROM ( SELECT NULL AS x ) js1 diff --git a/tests/queries/0_stateless/01076_predicate_optimizer_with_view.reference b/tests/queries/0_stateless/01076_predicate_optimizer_with_view.reference index dfab41b5e4c..620c5c7c8d1 100644 --- a/tests/queries/0_stateless/01076_predicate_optimizer_with_view.reference +++ b/tests/queries/0_stateless/01076_predicate_optimizer_with_view.reference @@ -3,7 +3,7 @@ SELECT id, name, value -FROM +FROM ( SELECT * FROM default.test @@ -15,7 +15,7 @@ SELECT id, name, value -FROM +FROM ( SELECT * FROM default.test @@ -23,7 +23,7 @@ FROM ) AS test_view WHERE id = 2 SELECT id -FROM +FROM ( SELECT * FROM default.test @@ -31,7 +31,7 @@ FROM ) AS test_view WHERE id = 1 SELECT id -FROM +FROM ( SELECT * FROM default.test diff --git a/tests/queries/0_stateless/01083_expressions_in_engine_arguments.reference b/tests/queries/0_stateless/01083_expressions_in_engine_arguments.reference index 2a5d7e6da32..b25cfadd0ec 100644 --- a/tests/queries/0_stateless/01083_expressions_in_engine_arguments.reference +++ b/tests/queries/0_stateless/01083_expressions_in_engine_arguments.reference @@ -6,6 +6,6 @@ CREATE TABLE default.distributed\n(\n `n` Int8\n)\nENGINE = Distributed(\'tes CREATE TABLE default.distributed_tf\n(\n `n` Int8\n) AS cluster(\'test_shard_localhost\', \'default\', \'buffer\') CREATE TABLE default.url\n(\n `n` UInt64,\n `col` String\n)\nENGINE = URL(\'https://localhost:8443/?query=select+n,+_table+from+default.merge+format+CSV\', \'CSV\') CREATE TABLE default.rich_syntax\n(\n `n` Int64\n) AS remote(\'localhos{x|y|t}\', cluster(\'test_shard_localhost\', remote(\'127.0.0.{1..4}\', \'default\', \'view\'))) -CREATE VIEW default.view\n(\n `n` Int64\n) AS\nSELECT toInt64(n) AS n\nFROM \n(\n SELECT toString(n) AS n\n FROM default.merge\n WHERE _table != \'qwerty\'\n ORDER BY _table ASC\n)\nUNION ALL\nSELECT *\nFROM default.file +CREATE VIEW default.view\n(\n `n` Int64\n) AS\nSELECT toInt64(n) AS n\nFROM\n(\n SELECT toString(n) AS n\n FROM default.merge\n WHERE _table != \'qwerty\'\n ORDER BY _table ASC\n)\nUNION ALL\nSELECT *\nFROM default.file CREATE DICTIONARY default.dict\n(\n `n` UInt64,\n `col` String DEFAULT \'42\'\n)\nPRIMARY KEY n\nSOURCE(CLICKHOUSE(HOST \'localhost\' PORT 9440 SECURE 1 USER \'default\' TABLE \'url\'))\nLIFETIME(MIN 0 MAX 1)\nLAYOUT(CACHE(SIZE_IN_CELLS 1)) 16 diff --git a/tests/queries/0_stateless/01245_limit_infinite_sources.sql b/tests/queries/0_stateless/01245_limit_infinite_sources.sql index 803a2d14c39..05680d86a33 100644 --- a/tests/queries/0_stateless/01245_limit_infinite_sources.sql +++ b/tests/queries/0_stateless/01245_limit_infinite_sources.sql @@ -1,5 +1,5 @@ SELECT number -FROM +FROM ( SELECT zero AS number FROM remote('127.0.0.2', system.zeros) diff --git a/tests/queries/0_stateless/01271_optimize_arithmetic_operations_in_aggr_func.reference b/tests/queries/0_stateless/01271_optimize_arithmetic_operations_in_aggr_func.reference index 669221005f4..b50519b9b3a 100644 --- a/tests/queries/0_stateless/01271_optimize_arithmetic_operations_in_aggr_func.reference +++ b/tests/queries/0_stateless/01271_optimize_arithmetic_operations_in_aggr_func.reference @@ -3,7 +3,7 @@ SELECT sum(1 + n), sum(n - 1), sum(1 - n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -13,7 +13,7 @@ SELECT 2 * sum(n), sum(n) / 2, sum(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -23,7 +23,7 @@ SELECT 1 + min(n), min(n) - 1, 1 - min(n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -33,7 +33,7 @@ SELECT 2 * min(n), min(n) / 2, min(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -43,7 +43,7 @@ SELECT 1 + max(n), max(n) - 1, 1 - max(n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -53,7 +53,7 @@ SELECT 2 * max(n), max(n) / 2, max(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -63,7 +63,7 @@ SELECT sum(-1 + n), sum(n - -1), sum(-1 - n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -73,7 +73,7 @@ SELECT -2 * sum(n), sum(n) / -2, sum(-1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -83,7 +83,7 @@ SELECT -1 + min(n), min(n) - -1, -1 - min(n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -93,7 +93,7 @@ SELECT -2 * max(n), max(n) / -2, min(-1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -103,7 +103,7 @@ SELECT -1 + max(n), max(n) - -1, -1 - max(n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -113,7 +113,7 @@ SELECT -2 * min(n), min(n) / -2, max(-1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -123,7 +123,7 @@ SELECT sum(abs(2) + n), sum(n - abs(2)), sum(1 - abs(2)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -133,7 +133,7 @@ SELECT sum(abs(2) * n), sum(n / abs(2)), sum(1 / abs(2)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -143,7 +143,7 @@ SELECT min(abs(2) + n), min(n - abs(2)), 1 - min(abs(2)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -153,7 +153,7 @@ SELECT min(abs(2) * n), min(n / abs(2)), min(1 / abs(2)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -163,7 +163,7 @@ SELECT max(abs(2) + n), max(n - abs(2)), 1 - max(abs(2)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -173,7 +173,7 @@ SELECT max(abs(2) * n), max(n / abs(2)), max(1 / abs(2)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -183,7 +183,7 @@ SELECT sum(abs(n) + n), sum(n - abs(n)), sum(1 - abs(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -193,7 +193,7 @@ SELECT sum(abs(n) * n), sum(n / abs(n)), sum(1 / abs(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -203,7 +203,7 @@ SELECT min(abs(n) + n), min(n - abs(n)), 1 - min(abs(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -213,7 +213,7 @@ SELECT min(abs(n) * n), min(n / abs(n)), min(1 / abs(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -223,7 +223,7 @@ SELECT max(abs(n) + n), max(n - abs(n)), 1 - max(abs(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -233,7 +233,7 @@ SELECT max(abs(n) * n), max(n / abs(n)), max(1 / abs(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -243,7 +243,7 @@ SELECT sum(1 + (n * n)), sum((n * n) - 1), sum(1 - (n * n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -253,7 +253,7 @@ SELECT sum((2 * n) * n), sum(n * n) / 2, sum((1 / n) * n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -263,7 +263,7 @@ SELECT 1 + min(n * n), min(n * n) - 1, 1 - min(n * n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -273,7 +273,7 @@ SELECT min((2 * n) * n), min(n * n) / 2, min((1 / n) * n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -283,7 +283,7 @@ SELECT 1 + max(n * n), max(n * n) - 1, 1 - max(n * n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -293,7 +293,7 @@ SELECT max((2 * n) * n), max(n * n) / 2, max((1 / n) * n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -303,7 +303,7 @@ SELECT sum((1 + 1) + n), sum((1 + n) - 1), sum((1 + 1) - n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -313,7 +313,7 @@ SELECT sum(1 + (2 * n)), sum(1 + (n / 2)), sum(1 + (1 / n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -323,7 +323,7 @@ SELECT min((1 + 1) + n), (1 + min(n)) - 1, min((1 + 1) - n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -333,7 +333,7 @@ SELECT 1 + min(2 * n), 1 + min(n / 2), 1 + min(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -343,7 +343,7 @@ SELECT max((1 + 1) + n), (1 + max(n)) - 1, max((1 + 1) - n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -353,7 +353,7 @@ SELECT 1 + max(2 * n), 1 + max(n / 2), 1 + max(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -363,7 +363,7 @@ SELECT sum((-1 + n) + -1), sum((n - -1) + -1), sum((-1 - n) + -1) -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -373,7 +373,7 @@ SELECT (-2 * sum(n)) * -1, (sum(n) / -2) / -1, sum(-1 / n) / -1 -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -383,7 +383,7 @@ SELECT (-1 + min(n)) + -1, (min(n) - -1) + -1, (-1 - min(n)) + -1 -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -393,7 +393,7 @@ SELECT (-2 * min(n)) * -1, (min(n) / -2) / -1, max(-1 / n) / -1 -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -403,7 +403,7 @@ SELECT (-1 + max(n)) + -1, (max(n) - -1) + -1, (-1 - max(n)) + -1 -FROM +FROM ( SELECT number AS n FROM numbers(10) @@ -413,43 +413,43 @@ SELECT (-2 * max(n)) * -1, (max(n) / -2) / -1, min(-1 / n) / -1 -FROM +FROM ( SELECT number AS n FROM numbers(10) ) SELECT ((sum(n + 1) + sum(1 + n)) + sum(n - 1)) + sum(1 - n) -FROM +FROM ( SELECT number AS n FROM numbers(10) ) SELECT (((sum(n) * 2) + (2 * sum(n))) + (sum(n) / 2)) + sum(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) ) SELECT (((min(n) + 1) + (1 + min(n))) + (min(n) - 1)) + (1 - min(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) ) SELECT (((min(n) * 2) + (2 * min(n))) + (min(n) / 2)) + min(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) ) SELECT (((max(n) + 1) + (1 + max(n))) + (max(n) - 1)) + (1 - max(n)) -FROM +FROM ( SELECT number AS n FROM numbers(10) ) SELECT (((max(n) * 2) + (2 * max(n))) + (max(n) / 2)) + max(1 / n) -FROM +FROM ( SELECT number AS n FROM numbers(10) diff --git a/tests/queries/0_stateless/01305_duplicate_order_by_and_distinct.reference b/tests/queries/0_stateless/01305_duplicate_order_by_and_distinct.reference index c076e56a91b..10f8bbfd392 100644 --- a/tests/queries/0_stateless/01305_duplicate_order_by_and_distinct.reference +++ b/tests/queries/0_stateless/01305_duplicate_order_by_and_distinct.reference @@ -1,8 +1,8 @@ SELECT number -FROM +FROM ( SELECT number - FROM + FROM ( SELECT DISTINCT number FROM numbers(3) @@ -13,10 +13,10 @@ ORDER BY number ASC 1 2 SELECT DISTINCT number -FROM +FROM ( SELECT DISTINCT number - FROM + FROM ( SELECT DISTINCT number FROM numbers(3) @@ -29,10 +29,10 @@ ORDER BY number ASC 1 2 SELECT number -FROM +FROM ( SELECT number - FROM + FROM ( SELECT DISTINCT number % 2 AS number FROM numbers(3) @@ -42,10 +42,10 @@ ORDER BY number ASC 0 1 SELECT DISTINCT number -FROM +FROM ( SELECT DISTINCT number - FROM + FROM ( SELECT DISTINCT number % 2 AS number FROM numbers(3) diff --git a/tests/queries/0_stateless/01321_aggregate_functions_of_group_by_keys.reference b/tests/queries/0_stateless/01321_aggregate_functions_of_group_by_keys.reference index 5eaaf24208e..555593d04bc 100644 --- a/tests/queries/0_stateless/01321_aggregate_functions_of_group_by_keys.reference +++ b/tests/queries/0_stateless/01321_aggregate_functions_of_group_by_keys.reference @@ -74,7 +74,7 @@ GROUP BY number % 5 ORDER BY a ASC SELECT foo -FROM +FROM ( SELECT number AS foo FROM numbers(1) @@ -155,7 +155,7 @@ GROUP BY number % 5 ORDER BY a ASC SELECT foo -FROM +FROM ( SELECT anyLast(number) AS foo FROM numbers(1) diff --git a/tests/queries/0_stateless/01323_redundant_functions_in_order_by.reference b/tests/queries/0_stateless/01323_redundant_functions_in_order_by.reference index c8421b9869e..b32ad433730 100644 --- a/tests/queries/0_stateless/01323_redundant_functions_in_order_by.reference +++ b/tests/queries/0_stateless/01323_redundant_functions_in_order_by.reference @@ -16,21 +16,21 @@ 2 2 3 3 SELECT groupArray(x) -FROM +FROM ( SELECT number AS x FROM numbers(3) ORDER BY x ASC ) SELECT groupArray(x) -FROM +FROM ( SELECT number AS x FROM numbers(3) ORDER BY x ASC ) SELECT groupArray(x) -FROM +FROM ( SELECT number AS x FROM numbers(3) @@ -43,7 +43,7 @@ SELECT a, b, c -FROM +FROM ( SELECT number + 2 AS key FROM numbers(4) @@ -84,7 +84,7 @@ ORDER BY 2 2 3 3 SELECT groupArray(x) -FROM +FROM ( SELECT number AS x FROM numbers(3) @@ -93,7 +93,7 @@ FROM exp(x) ASC ) SELECT groupArray(x) -FROM +FROM ( SELECT number AS x FROM numbers(3) @@ -102,7 +102,7 @@ FROM exp(exp(x)) ASC ) SELECT groupArray(x) -FROM +FROM ( SELECT number AS x FROM numbers(3) @@ -115,7 +115,7 @@ SELECT a, b, c -FROM +FROM ( SELECT number + 2 AS key FROM numbers(4) diff --git a/tests/queries/0_stateless/01372_wrong_order_by_removal.reference b/tests/queries/0_stateless/01372_wrong_order_by_removal.reference index f1f1bcef6e5..0c4d92a26b9 100644 --- a/tests/queries/0_stateless/01372_wrong_order_by_removal.reference +++ b/tests/queries/0_stateless/01372_wrong_order_by_removal.reference @@ -1,7 +1,7 @@ SELECT k, groupArrayMovingSum(v) -FROM +FROM ( SELECT k, diff --git a/tests/queries/0_stateless/01390_remove_injective_in_uniq.reference b/tests/queries/0_stateless/01390_remove_injective_in_uniq.reference index 94e1dbc5da7..eaff98b39cb 100644 --- a/tests/queries/0_stateless/01390_remove_injective_in_uniq.reference +++ b/tests/queries/0_stateless/01390_remove_injective_in_uniq.reference @@ -4,7 +4,7 @@ SELECT uniqHLL12(x), uniqCombined(x), uniqCombined64(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -15,7 +15,7 @@ SELECT uniqHLL12(x + y), uniqCombined(x + y), uniqCombined64(x + y) -FROM +FROM ( SELECT number % 2 AS x, @@ -28,7 +28,7 @@ SELECT uniqHLL12(x), uniqCombined(x), uniqCombined64(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -39,7 +39,7 @@ SELECT uniqHLL12(x), uniqCombined(x), uniqCombined64(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -50,7 +50,7 @@ SELECT uniqHLL12(x), uniqCombined(x), uniqCombined64(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -61,13 +61,13 @@ SELECT uniqHLL12(x), uniqCombined(x), uniqCombined64(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqExact(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -80,7 +80,7 @@ SELECT uniqHLL12(x), uniqCombined(x), uniqCombined64(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -91,7 +91,7 @@ SELECT uniqHLL12(x + y), uniqCombined(x + y), uniqCombined64(x + y) -FROM +FROM ( SELECT number % 2 AS x, @@ -104,7 +104,7 @@ SELECT uniqHLL12(-x), uniqCombined(-x), uniqCombined64(-x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -115,7 +115,7 @@ SELECT uniqHLL12(bitNot(x)), uniqCombined(bitNot(x)), uniqCombined64(bitNot(x)) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -126,7 +126,7 @@ SELECT uniqHLL12(bitNot(-x)), uniqCombined(bitNot(-x)), uniqCombined64(bitNot(-x)) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) @@ -137,13 +137,13 @@ SELECT uniqHLL12(-bitNot(-x)), uniqCombined(-bitNot(-x)), uniqCombined64(-bitNot(-x)) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqExact(-bitNot(-x)) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) diff --git a/tests/queries/0_stateless/01412_row_from_totals.sql b/tests/queries/0_stateless/01412_row_from_totals.sql index 170eb06721a..63c2a111369 100644 --- a/tests/queries/0_stateless/01412_row_from_totals.sql +++ b/tests/queries/0_stateless/01412_row_from_totals.sql @@ -11,7 +11,7 @@ insert into tracking_events_tmp select 2, '2020-07-10' from numbers(1881); insert into tracking_events_tmp select 2, '2020-07-11' from numbers(1623); SELECT EventDate -FROM +FROM ( SELECT EventDate FROM tracking_events_tmp AS t1 diff --git a/tests/queries/0_stateless/01414_push_predicate_when_contains_with_clause.reference b/tests/queries/0_stateless/01414_push_predicate_when_contains_with_clause.reference index 13c8fe551c7..bbda231662e 100644 --- a/tests/queries/0_stateless/01414_push_predicate_when_contains_with_clause.reference +++ b/tests/queries/0_stateless/01414_push_predicate_when_contains_with_clause.reference @@ -3,7 +3,7 @@ SELECT number, square_number -FROM +FROM ( WITH number * 2 AS square_number SELECT diff --git a/tests/queries/0_stateless/01455_duplicate_distinct_optimization.reference b/tests/queries/0_stateless/01455_duplicate_distinct_optimization.reference index 2c54899f9f5..82e887e1b92 100644 --- a/tests/queries/0_stateless/01455_duplicate_distinct_optimization.reference +++ b/tests/queries/0_stateless/01455_duplicate_distinct_optimization.reference @@ -1,13 +1,13 @@ SELECT DISTINCT number FROM numbers(1) SELECT number -FROM +FROM ( SELECT DISTINCT number FROM numbers(1) ) SELECT DISTINCT number * 2 -FROM +FROM ( SELECT DISTINCT number * 2, @@ -15,7 +15,7 @@ FROM FROM numbers(1) ) SELECT number -FROM +FROM ( SELECT DISTINCT number * 2 AS number FROM numbers(1) @@ -23,7 +23,7 @@ FROM SELECT b, a -FROM +FROM ( SELECT DISTINCT number % 2 AS a, @@ -31,7 +31,7 @@ FROM FROM numbers(100) ) SELECT DISTINCT a -FROM +FROM ( SELECT DISTINCT number % 2 AS a, @@ -39,10 +39,10 @@ FROM FROM numbers(100) ) SELECT a -FROM +FROM ( SELECT DISTINCT a - FROM + FROM ( SELECT DISTINCT number % 2 AS a, @@ -51,12 +51,12 @@ FROM ) ) SELECT DISTINCT a -FROM +FROM ( SELECT a, b - FROM + FROM ( SELECT DISTINCT number % 2 AS a, @@ -67,12 +67,12 @@ FROM SELECT a, b -FROM +FROM ( SELECT b, a - FROM + FROM ( SELECT DISTINCT number AS a, @@ -83,13 +83,13 @@ FROM SELECT a, b -FROM +FROM ( SELECT b, a, a + b - FROM + FROM ( SELECT DISTINCT number % 2 AS a, @@ -98,10 +98,10 @@ FROM ) ) SELECT DISTINCT a -FROM +FROM ( SELECT a - FROM + FROM ( SELECT DISTINCT number % 2 AS a, @@ -110,21 +110,21 @@ FROM ) ) SELECT DISTINCT number -FROM +FROM ( SELECT DISTINCT number FROM numbers(1) ) AS t1 CROSS JOIN numbers(2) AS t2 SELECT number -FROM +FROM ( SELECT DISTINCT number FROM numbers(1) AS t1 CROSS JOIN numbers(2) AS t2 ) SELECT DISTINCT number -FROM +FROM ( SELECT DISTINCT number FROM numbers(1) diff --git a/tests/queries/0_stateless/01495_subqueries_in_with_statement_4.reference b/tests/queries/0_stateless/01495_subqueries_in_with_statement_4.reference index 6a713b14181..c83f681fc54 100644 --- a/tests/queries/0_stateless/01495_subqueries_in_with_statement_4.reference +++ b/tests/queries/0_stateless/01495_subqueries_in_with_statement_4.reference @@ -1,5 +1,5 @@ 0 0 -WITH it AS +WITH it AS ( SELECT * FROM numbers(1) @@ -7,4 +7,5 @@ WITH it AS SELECT number, number -FROM it AS i +FROM +it AS i diff --git a/tests/queries/0_stateless/01515_with_global_and_with_propagation.reference b/tests/queries/0_stateless/01515_with_global_and_with_propagation.reference index 76c46dd798f..dd611b45ccd 100644 --- a/tests/queries/0_stateless/01515_with_global_and_with_propagation.reference +++ b/tests/queries/0_stateless/01515_with_global_and_with_propagation.reference @@ -13,7 +13,7 @@ WITH 1 AS x SELECT x WITH 1 AS x SELECT x -FROM +FROM ( WITH 1 AS x SELECT x @@ -22,7 +22,7 @@ WITH 1 AS x SELECT y, x -FROM +FROM ( WITH 2 AS x SELECT 2 AS y @@ -39,7 +39,7 @@ WITH 2 AS x SELECT x WITH 5 AS q1, - x AS + x AS ( WITH 5 AS q1 SELECT @@ -51,4 +51,5 @@ WITH SELECT b, a -FROM x +FROM +x diff --git a/tests/queries/0_stateless/01532_having_with_totals.sql b/tests/queries/0_stateless/01532_having_with_totals.sql index 10f55c8c135..290799c1354 100644 --- a/tests/queries/0_stateless/01532_having_with_totals.sql +++ b/tests/queries/0_stateless/01532_having_with_totals.sql @@ -3,7 +3,7 @@ create table local_t engine Log as select 1 a; SELECT '127.0.0.{1,2}'; SELECT * -FROM +FROM ( SELECT a FROM remote('127.0.0.{1,2}', currentDatabase(), local_t) @@ -17,7 +17,7 @@ WHERE a IN SELECT '127.0.0.1'; SELECT * -FROM +FROM ( SELECT a FROM remote('127.0.0.1', currentDatabase(), local_t) diff --git a/tests/queries/0_stateless/01532_min_max_with_modifiers.sql b/tests/queries/0_stateless/01532_min_max_with_modifiers.sql index 0c8651c0f01..364b110d8c1 100644 --- a/tests/queries/0_stateless/01532_min_max_with_modifiers.sql +++ b/tests/queries/0_stateless/01532_min_max_with_modifiers.sql @@ -11,7 +11,7 @@ SELECT min(x) AS lower, max(x) + 1 AS upper, upper - lower AS range -FROM +FROM ( SELECT arrayJoin([1, 2]) AS x ) diff --git a/tests/queries/0_stateless/01559_aggregate_null_for_empty_fix.sql b/tests/queries/0_stateless/01559_aggregate_null_for_empty_fix.sql index 5955dee37f8..3434a049073 100644 --- a/tests/queries/0_stateless/01559_aggregate_null_for_empty_fix.sql +++ b/tests/queries/0_stateless/01559_aggregate_null_for_empty_fix.sql @@ -1,5 +1,5 @@ SELECT MAX(aggr) -FROM +FROM ( SELECT MAX(-1) AS aggr FROM system.one @@ -11,7 +11,7 @@ FROM ); SELECT MaX(aggr) -FROM +FROM ( SELECT mAX(-1) AS aggr FROM system.one @@ -22,7 +22,7 @@ FROM WHERE 1 ); SELECT MaX(aggr) -FROM +FROM ( SELECT mAX(-1) AS aggr FROM system.one @@ -33,7 +33,7 @@ FROM WHERE 1 ); SELECT MaX(aggr) -FROM +FROM ( SELECT mAX(-1) AS aggr FROM system.one @@ -45,7 +45,7 @@ FROM ); SET aggregate_functions_null_for_empty=1; SELECT MAX(aggr) -FROM +FROM ( SELECT MAX(-1) AS aggr FROM system.one @@ -57,7 +57,7 @@ FROM ); SELECT MaX(aggr) -FROM +FROM ( SELECT mAX(-1) AS aggr FROM system.one @@ -68,7 +68,7 @@ FROM WHERE 1 ); SELECT MaX(aggr) -FROM +FROM ( SELECT mAX(-1) AS aggr FROM system.one @@ -79,7 +79,7 @@ FROM WHERE 1 ); SELECT MaX(aggr) -FROM +FROM ( SELECT mAX(-1) AS aggr FROM system.one diff --git a/tests/queries/0_stateless/01560_DateTime_and_DateTime64_comparision.sql b/tests/queries/0_stateless/01560_DateTime_and_DateTime64_comparision.sql index c5e677570ea..2c3ae41864e 100644 --- a/tests/queries/0_stateless/01560_DateTime_and_DateTime64_comparision.sql +++ b/tests/queries/0_stateless/01560_DateTime_and_DateTime64_comparision.sql @@ -31,7 +31,7 @@ SELECT dt64 != dt, toDateTime(dt64) != dt, dt64 != toDateTime64(dt, 1, 'UTC') -FROM +FROM ( WITH toDateTime('2015-05-18 07:40:11') as value SELECT diff --git a/tests/queries/0_stateless/01560_monotonicity_check_multiple_args_bug.sql b/tests/queries/0_stateless/01560_monotonicity_check_multiple_args_bug.sql index befc13be8eb..b475a5bdd3c 100644 --- a/tests/queries/0_stateless/01560_monotonicity_check_multiple_args_bug.sql +++ b/tests/queries/0_stateless/01560_monotonicity_check_multiple_args_bug.sql @@ -1,7 +1,7 @@ WITH arrayJoin(range(2)) AS delta SELECT toDate(time) + toIntervalDay(delta) AS dt -FROM +FROM ( SELECT toDateTime('2020.11.12 19:02:04') AS time ) @@ -10,7 +10,7 @@ ORDER BY dt ASC; WITH arrayJoin([0, 1]) AS delta SELECT toDate(time) + toIntervalDay(delta) AS dt -FROM +FROM ( SELECT toDateTime('2020.11.12 19:02:04') AS time ) diff --git a/tests/queries/0_stateless/01582_deterministic_function_with_predicate.reference b/tests/queries/0_stateless/01582_deterministic_function_with_predicate.reference index a1b4bfdcc03..b764691f5b6 100644 --- a/tests/queries/0_stateless/01582_deterministic_function_with_predicate.reference +++ b/tests/queries/0_stateless/01582_deterministic_function_with_predicate.reference @@ -1,8 +1,8 @@ SELECT count() -FROM +FROM ( SELECT number - FROM + FROM ( SELECT number FROM numbers(1000000) diff --git a/tests/queries/0_stateless/01593_functions_in_order_by.reference b/tests/queries/0_stateless/01593_functions_in_order_by.reference index 534b29af3e6..4f4ea02f95c 100644 --- a/tests/queries/0_stateless/01593_functions_in_order_by.reference +++ b/tests/queries/0_stateless/01593_functions_in_order_by.reference @@ -1,7 +1,7 @@ SELECT msg, toDateTime(intDiv(ms, 1000)) AS time -FROM +FROM ( SELECT \'hello\' AS msg, diff --git a/tests/queries/0_stateless/01593_functions_in_order_by.sql b/tests/queries/0_stateless/01593_functions_in_order_by.sql index 2d38e45fff7..5aa6aef9e12 100644 --- a/tests/queries/0_stateless/01593_functions_in_order_by.sql +++ b/tests/queries/0_stateless/01593_functions_in_order_by.sql @@ -1,6 +1,6 @@ EXPLAIN SYNTAX SELECT msg, toDateTime(intDiv(ms, 1000)) AS time -FROM +FROM ( SELECT 'hello' AS msg, diff --git a/tests/queries/0_stateless/01635_nullable_fuzz.sql b/tests/queries/0_stateless/01635_nullable_fuzz.sql index c134578b221..f49fe39d350 100644 --- a/tests/queries/0_stateless/01635_nullable_fuzz.sql +++ b/tests/queries/0_stateless/01635_nullable_fuzz.sql @@ -4,7 +4,7 @@ SELECT '', number, NULL AS k -FROM +FROM ( SELECT materialize(NULL) OR materialize(-9223372036854775808), diff --git a/tests/queries/0_stateless/01636_nullable_fuzz2.sql b/tests/queries/0_stateless/01636_nullable_fuzz2.sql index a40da51c38c..49ee7626b4e 100644 --- a/tests/queries/0_stateless/01636_nullable_fuzz2.sql +++ b/tests/queries/0_stateless/01636_nullable_fuzz2.sql @@ -13,7 +13,7 @@ insert into tracking_events_tmp select 2, '2020-07-10' from numbers(1881); insert into tracking_events_tmp select 2, '2020-07-11' from numbers(1623); SELECT EventDate -FROM +FROM ( SELECT EventDate FROM tracking_events_tmp AS t1 diff --git a/tests/queries/0_stateless/01650_expressions_merge_bug.sql b/tests/queries/0_stateless/01650_expressions_merge_bug.sql index f28f663b2d4..3cab4dbd5a6 100644 --- a/tests/queries/0_stateless/01650_expressions_merge_bug.sql +++ b/tests/queries/0_stateless/01650_expressions_merge_bug.sql @@ -7,7 +7,7 @@ SELECT 9223372036854775807 ), NULL -FROM +FROM ( SELECT DISTINCT NULL, diff --git a/tests/queries/0_stateless/01670_neighbor_lc_bug.sql b/tests/queries/0_stateless/01670_neighbor_lc_bug.sql index de9afcf1495..2d99225aa89 100644 --- a/tests/queries/0_stateless/01670_neighbor_lc_bug.sql +++ b/tests/queries/0_stateless/01670_neighbor_lc_bug.sql @@ -33,7 +33,7 @@ SELECT val_low, neighbor(val_low, -1) AS low_m1, neighbor(val_low, 1) AS low_p1 -FROM +FROM ( SELECT * FROM neighbor_test diff --git a/tests/queries/0_stateless/01732_explain_syntax_union_query.reference b/tests/queries/0_stateless/01732_explain_syntax_union_query.reference index fe5eb01a7ed..ccafa916b9f 100644 --- a/tests/queries/0_stateless/01732_explain_syntax_union_query.reference +++ b/tests/queries/0_stateless/01732_explain_syntax_union_query.reference @@ -7,7 +7,7 @@ UNION ALL SELECT 1 UNION ALL SELECT 1 - +- SELECT 1 UNION ALL ( @@ -19,9 +19,9 @@ UNION ALL ) UNION ALL SELECT 1 - +- SELECT x -FROM +FROM ( SELECT 1 AS x UNION ALL @@ -35,9 +35,9 @@ FROM UNION ALL SELECT 1 ) - +- SELECT x -FROM +FROM ( SELECT 1 AS x UNION ALL @@ -45,15 +45,15 @@ FROM UNION ALL SELECT 1 ) - +- SELECT 1 UNION DISTINCT SELECT 1 UNION DISTINCT SELECT 1 - +- SELECT 1 - +- ( SELECT 1 diff --git a/tests/queries/0_stateless/01732_explain_syntax_union_query.sql b/tests/queries/0_stateless/01732_explain_syntax_union_query.sql index 0dd1e19e765..c35021090f1 100644 --- a/tests/queries/0_stateless/01732_explain_syntax_union_query.sql +++ b/tests/queries/0_stateless/01732_explain_syntax_union_query.sql @@ -13,7 +13,7 @@ UNION ALL SELECT 1 ); -SELECT ' '; +SELECT '-'; EXPLAIN SYNTAX SELECT 1 @@ -30,7 +30,7 @@ UNION ALL SELECT 1 ); -SELECT ' '; +SELECT '-'; EXPLAIN SYNTAX SELECT x @@ -51,11 +51,11 @@ FROM ) ); -SELECT ' '; +SELECT '-'; EXPLAIN SYNTAX SELECT x -FROM +FROM ( SELECT 1 AS x UNION ALL @@ -66,7 +66,7 @@ FROM ) ); -SELECT ' '; +SELECT '-'; EXPLAIN SYNTAX SELECT 1 @@ -75,12 +75,12 @@ SELECT 1 UNION DISTINCT SELECT 1; -SELECT ' '; +SELECT '-'; EXPLAIN SYNTAX (((((((((((((((SELECT 1))))))))))))))); -SELECT ' '; +SELECT '-'; EXPLAIN SYNTAX (((((((((((((((SELECT 1 UNION DISTINCT SELECT 1))) UNION DISTINCT SELECT 1)))) UNION ALL SELECT 1)))))))); diff --git a/tests/queries/0_stateless/01754_clickhouse_format_backslash.reference b/tests/queries/0_stateless/01754_clickhouse_format_backslash.reference index 328483d9867..28519b2f92f 100644 --- a/tests/queries/0_stateless/01754_clickhouse_format_backslash.reference +++ b/tests/queries/0_stateless/01754_clickhouse_format_backslash.reference @@ -1,5 +1,5 @@ SELECT * \ -FROM \ +FROM \ ( \ SELECT 1 AS x \ UNION ALL \ diff --git a/tests/queries/0_stateless/01798_uniq_theta_sketch.reference b/tests/queries/0_stateless/01798_uniq_theta_sketch.reference index e5f3fe4911e..0455a06036f 100644 --- a/tests/queries/0_stateless/01798_uniq_theta_sketch.reference +++ b/tests/queries/0_stateless/01798_uniq_theta_sketch.reference @@ -32,13 +32,13 @@ uniqTheta decimals (101,101,101) uniqTheta remove injective SELECT uniqTheta(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(x + y) -FROM +FROM ( SELECT number % 2 AS x, @@ -46,37 +46,37 @@ FROM FROM numbers(10) ) SELECT uniqTheta(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(x + y) -FROM +FROM ( SELECT number % 2 AS x, @@ -84,25 +84,25 @@ FROM FROM numbers(10) ) SELECT uniqTheta(-x) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(bitNot(x)) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(bitNot(-x)) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) ) SELECT uniqTheta(-bitNot(-x)) -FROM +FROM ( SELECT number % 2 AS x FROM numbers(10) diff --git a/tests/queries/0_stateless/01874_select_from_trailing_whitespaces.reference b/tests/queries/0_stateless/01874_select_from_trailing_whitespaces.reference new file mode 100644 index 00000000000..a52505659d1 --- /dev/null +++ b/tests/queries/0_stateless/01874_select_from_trailing_whitespaces.reference @@ -0,0 +1,114 @@ +# select * from system.one a +SELECT * +FROM system.one AS a +# /* oneline */ select * from system.one a +SELECT * FROM system.one AS a +# select * from (select * from system.one) b, system.one a +SELECT * +FROM +( + SELECT * + FROM system.one +) AS b, system.one AS a +# /* oneline */ select * from (select * from system.one) b, system.one a +SELECT * FROM (SELECT * FROM system.one) AS b, system.one AS a +# select * from system.one a, (select * from system.one) b, system.one c +SELECT * +FROM system.one AS a, +( + SELECT * + FROM system.one +) AS b, system.one AS c +# /* oneline */ select * from system.one a, (select * from system.one) b, system.one c +SELECT * FROM system.one AS a, (SELECT * FROM system.one) AS b, system.one AS c +# select * from system.one a, (select * from system.one) b, system.one c, (select * from system.one) d +SELECT * +FROM system.one AS a, +( + SELECT * + FROM system.one +) AS b, system.one AS c, +( + SELECT * + FROM system.one +) AS d +# /* oneline */ select * from system.one a, (select * from system.one) b, system.one c, (select * from system.one) d +SELECT * FROM system.one AS a, (SELECT * FROM system.one) AS b, system.one AS c, (SELECT * FROM system.one) AS d +# select * from system.one union all select * from system.one +SELECT * +FROM system.one +UNION ALL +SELECT * +FROM system.one +# /* oneline */ select * from system.one union all select * from system.one +SELECT * FROM system.one UNION ALL SELECT * FROM system.one +# select * from system.one union all (select * from system.one) +SELECT * +FROM system.one +UNION ALL +SELECT * +FROM system.one +# /* oneline */ select * from system.one union all (select * from system.one) +SELECT * FROM system.one UNION ALL SELECT * FROM system.one +# select 1 union all (select 1 union distinct select 1) +SELECT 1 +UNION ALL +( + SELECT 1 + UNION DISTINCT + SELECT 1 +) +# /* oneline */ select 1 union all (select 1 union distinct select 1) +SELECT 1 UNION ALL (SELECT 1 UNION DISTINCT SELECT 1) +# select * from system.one array join arr as row +SELECT * +FROM system.one +ARRAY JOIN arr AS row +# /* oneline */ select * from system.one array join arr as row +SELECT * FROM system.one ARRAY JOIN arr AS row +# select 1 in 1 +SELECT 1 IN (1) +# /* oneline */ select 1 in 1 +SELECT 1 IN (1) +# select 1 in (select 1) +SELECT 1 IN ( + SELECT 1 + ) +# /* oneline */ select 1 in (select 1) +SELECT 1 IN (SELECT 1) +# select 1 in f(1) +SELECT 1 IN f(1) +# /* oneline */ select 1 in f(1) +SELECT 1 IN f(1) +# select 1 in ((select 1) as sub) +SELECT 1 IN (( + SELECT 1 + ) AS sub) +# /* oneline */ select 1 in ((select 1) as sub) +SELECT 1 IN ((SELECT 1) AS sub) +# with it as ( select * from numbers(1) ) select it.number, i.number from it as i +WITH it AS + ( + SELECT * + FROM numbers(1) + ) +SELECT + it.number, + i.number +FROM it AS i +# /* oneline */ with it as ( select * from numbers(1) ) select it.number, i.number from it as i +WITH it AS (SELECT * FROM numbers(1)) SELECT it.number, i.number FROM it AS i +# SELECT x FROM ( SELECT 1 AS x UNION ALL ( SELECT 1 UNION ALL SELECT 1)) +SELECT x +FROM +( + SELECT 1 AS x + UNION ALL + ( + SELECT 1 + UNION ALL + SELECT 1 + ) +) +# /* oneline */ SELECT x FROM ( SELECT 1 AS x UNION ALL ( SELECT 1 UNION ALL SELECT 1)) +SELECT x FROM (SELECT 1 AS x UNION ALL (SELECT 1 UNION ALL SELECT 1)) diff --git a/tests/queries/0_stateless/01874_select_from_trailing_whitespaces.sh b/tests/queries/0_stateless/01874_select_from_trailing_whitespaces.sh new file mode 100755 index 00000000000..f416ac33d69 --- /dev/null +++ b/tests/queries/0_stateless/01874_select_from_trailing_whitespaces.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +set -e + +queries=( + "select * from system.one a" + "select * from (select * from system.one) b, system.one a" + "select * from system.one a, (select * from system.one) b, system.one c" + "select * from system.one a, (select * from system.one) b, system.one c, (select * from system.one) d" + "select * from system.one union all select * from system.one" + "select * from system.one union all (select * from system.one)" + "select 1 union all (select 1 union distinct select 1)" + "select * from system.one array join arr as row" + "select 1 in 1" + "select 1 in (select 1)" + "select 1 in f(1)" + "select 1 in ((select 1) as sub)" + "with it as ( select * from numbers(1) ) select it.number, i.number from it as i" + "SELECT x FROM ( SELECT 1 AS x UNION ALL ( SELECT 1 UNION ALL SELECT 1))" +) +for q in "${queries[@]}"; do + echo "# $q" + $CLICKHOUSE_FORMAT <<<"$q" + echo "# /* oneline */ $q" + $CLICKHOUSE_FORMAT --oneline <<<"$q" +done diff --git a/tests/queries/1_stateful/00031_array_enumerate_uniq.sql b/tests/queries/1_stateful/00031_array_enumerate_uniq.sql index 1898fc20579..f0392a17024 100644 --- a/tests/queries/1_stateful/00031_array_enumerate_uniq.sql +++ b/tests/queries/1_stateful/00031_array_enumerate_uniq.sql @@ -1,5 +1,5 @@ SELECT UserID, arrayEnumerateUniq(groupArray(SearchPhrase)) AS arr -FROM +FROM ( SELECT UserID, SearchPhrase FROM test.hits diff --git a/tests/queries/1_stateful/00063_loyalty_joins.sql b/tests/queries/1_stateful/00063_loyalty_joins.sql index 7713c65838c..1e7011ea909 100644 --- a/tests/queries/1_stateful/00063_loyalty_joins.sql +++ b/tests/queries/1_stateful/00063_loyalty_joins.sql @@ -23,7 +23,7 @@ ORDER BY loyalty ASC; SELECT loyalty, count() -FROM +FROM ( SELECT UserID FROM test.hits @@ -46,12 +46,12 @@ ORDER BY loyalty ASC; SELECT loyalty, count() -FROM +FROM ( SELECT loyalty, UserID - FROM + FROM ( SELECT UserID FROM test.hits @@ -81,7 +81,7 @@ FROM test.hits ANY INNER JOIN SELECT UserID, toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty - FROM + FROM ( SELECT UserID,