diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 92ae37123fa..a0c1e24b386 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -949,6 +949,11 @@ private: TestHint test_hint(test_mode, all_queries_text); if (test_hint.clientError() || test_hint.serverError()) processTextAsSingleQuery("SET send_logs_level = 'none'"); + + // Echo all queries if asked; makes for a more readable reference + // file. + if (test_hint.echoQueries()) + echo_queries = true; } /// Several queries separated by ';'. diff --git a/programs/client/TestHint.h b/programs/client/TestHint.h index 65666f4304c..f1998588261 100644 --- a/programs/client/TestHint.h +++ b/programs/client/TestHint.h @@ -19,6 +19,7 @@ namespace ErrorCodes /// Checks expected server and client error codes in testmode. /// To enable it add special comment after the query: "-- { serverError 60 }" or "-- { clientError 20 }". +/// Also you can enable echoing all queries by writing "-- { echo }". class TestHint { public: @@ -84,12 +85,14 @@ public: int serverError() const { return server_error; } int clientError() const { return client_error; } + bool echoQueries() const { return echo; } private: bool enabled = false; const String & query; int server_error = 0; int client_error = 0; + bool echo = false; void parse(const String & hint) { @@ -107,6 +110,8 @@ private: ss >> server_error; else if (item == "clientError") ss >> client_error; + else if (item == "echo") + echo = true; } } diff --git a/src/Interpreters/ExpressionAnalyzer.cpp b/src/Interpreters/ExpressionAnalyzer.cpp index 346c287f239..8e410c5bebd 100644 --- a/src/Interpreters/ExpressionAnalyzer.cpp +++ b/src/Interpreters/ExpressionAnalyzer.cpp @@ -474,8 +474,6 @@ bool ExpressionAnalyzer::makeWindowDescriptions(ActionsDAGPtr & actions) { for (const ASTFunction * function_node : windowFunctions()) { - fmt::print(stderr, "window function ast: {}\n", function_node->dumpTree()); - assert(function_node->is_window_function); // FIXME not thread-safe, should use a per-query counter. diff --git a/src/Parsers/ExpressionElementParsers.cpp b/src/Parsers/ExpressionElementParsers.cpp index 575d0331b08..cd9d8e921ef 100644 --- a/src/Parsers/ExpressionElementParsers.cpp +++ b/src/Parsers/ExpressionElementParsers.cpp @@ -396,8 +396,6 @@ bool ParserFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { return false; } - - fmt::print(stderr, "window function ast {}\n", function_node->dumpTree()); } node = function_node; diff --git a/tests/queries/0_stateless/01591_window_functions.reference b/tests/queries/0_stateless/01591_window_functions.reference new file mode 100644 index 00000000000..32574813f1e --- /dev/null +++ b/tests/queries/0_stateless/01591_window_functions.reference @@ -0,0 +1,92 @@ +select number, count() over (partition by intDiv(number, 3) order by number) from numbers(10); + +-- proper calculation across blocks + +0 1 +1 2 +2 3 +3 1 +4 2 +5 3 +6 1 +7 2 +8 3 +9 1 +select number, max(number) over (partition by intDiv(number, 3) order by number desc) from numbers(10) settings max_block_size = 2; + +-- not a window function + +2 2 +1 2 +0 2 +5 5 +4 5 +3 5 +8 8 +7 8 +6 8 +9 9 +select number, abs(number) over (partition by toString(intDiv(number, 3))) from numbers(10); -- { serverError 63 } + +-- no partition by + +select number, avg(number) over (order by number) from numbers(10); + +-- no order by + +0 0 +1 0 +2 1 +3 1 +4 2 +5 2 +6 3 +7 3 +8 4 +9 4 +select number, quantileExact(number) over (partition by intDiv(number, 3)) from numbers(10); + +-- can add an alias after window spec + +0 0 +1 1 +2 1 +3 3 +4 4 +5 4 +6 6 +7 7 +8 7 +9 9 +select number, quantileExact(number) over (partition by intDiv(number, 3)) q from numbers(10); + +-- can't reference it yet -- the window functions are calculated at the +-- last stage of select, after all other functions. + +0 0 +1 1 +2 1 +3 3 +4 4 +5 4 +6 6 +7 7 +8 7 +9 9 +select q * 10, quantileExact(number) over (partition by intDiv(number, 3)) q from numbers(10); -- { serverError 47 } + +-- should work in ORDER BY though + +select number, max(number) over (partition by intDiv(number, 3) order by number desc) m from numbers(10) order by m desc, number; + + +9 9 +6 8 +7 8 +8 8 +3 5 +4 5 +5 5 +0 2 +1 2 +2 2 diff --git a/tests/queries/0_stateless/01591_window_functions.sql b/tests/queries/0_stateless/01591_window_functions.sql new file mode 100644 index 00000000000..4a23eb9fa5c --- /dev/null +++ b/tests/queries/0_stateless/01591_window_functions.sql @@ -0,0 +1,27 @@ +-- { echo } + +-- just something basic +select number, count() over (partition by intDiv(number, 3) order by number) from numbers(10); + +-- proper calculation across blocks +select number, max(number) over (partition by intDiv(number, 3) order by number desc) from numbers(10) settings max_block_size = 2; + +-- not a window function +select number, abs(number) over (partition by toString(intDiv(number, 3))) from numbers(10); -- { serverError 63 } + +-- no partition by +select number, avg(number) over (order by number) from numbers(10); + +-- no order by +select number, quantileExact(number) over (partition by intDiv(number, 3)) from numbers(10); + +-- can add an alias after window spec +select number, quantileExact(number) over (partition by intDiv(number, 3)) q from numbers(10); + +-- can't reference it yet -- the window functions are calculated at the +-- last stage of select, after all other functions. +select q * 10, quantileExact(number) over (partition by intDiv(number, 3)) q from numbers(10); -- { serverError 47 } + +-- should work in ORDER BY though +select number, max(number) over (partition by intDiv(number, 3) order by number desc) m from numbers(10) order by m desc, number; +