提交 998bd178 编写于 作者: A Alexander Kuzmenkov

fix column name clash w/agg fns

also fix some test references influenced by the explain changes
上级 a3878755
...@@ -148,9 +148,9 @@ void QueryNormalizer::visit(ASTSelectQuery & select, const ASTPtr &, Data & data ...@@ -148,9 +148,9 @@ void QueryNormalizer::visit(ASTSelectQuery & select, const ASTPtr &, Data & data
/// Don't go into select query. It processes children itself. /// Don't go into select query. It processes children itself.
/// Do not go to the left argument of lambda expressions, so as not to replace the formal parameters /// Do not go to the left argument of lambda expressions, so as not to replace the formal parameters
/// on aliases in expressions of the form 123 AS x, arrayMap(x -> 1, [2]). /// on aliases in expressions of the form 123 AS x, arrayMap(x -> 1, [2]).
void QueryNormalizer::visitChildren(const ASTPtr & node, Data & data) void QueryNormalizer::visitChildren(ASTPtr & node, Data & data)
{ {
if (const auto * func_node = node->as<ASTFunction>()) if (auto * func_node = node->as<ASTFunction>())
{ {
if (func_node->tryGetQueryArgument()) if (func_node->tryGetQueryArgument())
{ {
...@@ -159,21 +159,25 @@ void QueryNormalizer::visitChildren(const ASTPtr & node, Data & data) ...@@ -159,21 +159,25 @@ void QueryNormalizer::visitChildren(const ASTPtr & node, Data & data)
/// Don't go into query argument. /// Don't go into query argument.
return; return;
} }
/// We skip the first argument. We also assume that the lambda function can not have parameters.
size_t first_pos = 0;
if (func_node->name == "lambda")
first_pos = 1;
if (func_node->arguments) // Process all function node children (arguments + window definition for
// window functions).
// We have to skip the first argument if it's the "lambda" function,
// because it contains formal parameters like x->x + 1;
const IAST * argument_to_skip = nullptr;
if (func_node->name == "lambda"
&& func_node->arguments
&& !func_node->arguments->children.empty())
{ {
auto & func_children = func_node->arguments->children; argument_to_skip = func_node->arguments->children[0].get();
}
for (size_t i = first_pos; i < func_children.size(); ++i) for (auto & child : func_node->children)
{
if (child.get() != argument_to_skip
&& needVisitChild(child))
{ {
auto & child = func_children[i]; visit(child, data);
if (needVisitChild(child))
visit(child, data);
} }
} }
} }
......
...@@ -69,7 +69,7 @@ private: ...@@ -69,7 +69,7 @@ private:
static void visit(ASTTablesInSelectQueryElement &, const ASTPtr &, Data &); static void visit(ASTTablesInSelectQueryElement &, const ASTPtr &, Data &);
static void visit(ASTSelectQuery &, const ASTPtr &, Data &); static void visit(ASTSelectQuery &, const ASTPtr &, Data &);
static void visitChildren(const ASTPtr &, Data & data); static void visitChildren(ASTPtr & node, Data & data);
}; };
} }
...@@ -39,6 +39,16 @@ void ASTFunction::appendColumnNameImpl(WriteBuffer & ostr) const ...@@ -39,6 +39,16 @@ void ASTFunction::appendColumnNameImpl(WriteBuffer & ostr) const
(*it)->appendColumnName(ostr); (*it)->appendColumnName(ostr);
} }
writeChar(')', ostr); writeChar(')', ostr);
if (is_window_function)
{
writeCString(" OVER (", ostr);
FormatSettings settings{ostr, true /* one_line */};
FormatState state;
FormatStateStacked frame;
appendWindowDescription(settings, state, frame);
writeCString(")", ostr);
}
} }
/** Get the text that identifies this element. */ /** Get the text that identifies this element. */
......
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
Header: x UInt8 Header: x UInt8
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
Header: dummy UInt8 Header: dummy UInt8
......
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Distinct Distinct
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Union Union
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
Expression (Projection + Before ORDER BY and SELECT) Expression (Projection + Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (SystemOne) ReadFromStorage (SystemOne)
...@@ -9,7 +9,7 @@ Expression (Projection) ...@@ -9,7 +9,7 @@ Expression (Projection)
MergingSorted (Merge sorted streams for ORDER BY) MergingSorted (Merge sorted streams for ORDER BY)
MergeSorting (Merge sorted blocks for ORDER BY) MergeSorting (Merge sorted blocks for ORDER BY)
PartialSorting (Sort each block for ORDER BY) PartialSorting (Sort each block for ORDER BY)
Expression (Before ORDER BY and SELECT) Expression (Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (MergeTree) ReadFromStorage (MergeTree)
SELECT SELECT
...@@ -21,7 +21,7 @@ LIMIT 10 ...@@ -21,7 +21,7 @@ LIMIT 10
Expression (Projection) Expression (Projection)
Limit (preliminary LIMIT) Limit (preliminary LIMIT)
FinishSorting FinishSorting
Expression (Before ORDER BY and SELECT) Expression (Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (MergeTree with order) ReadFromStorage (MergeTree with order)
SELECT SELECT
...@@ -35,7 +35,7 @@ LIMIT 10 ...@@ -35,7 +35,7 @@ LIMIT 10
Expression (Projection) Expression (Projection)
Limit (preliminary LIMIT) Limit (preliminary LIMIT)
FinishSorting FinishSorting
Expression (Before ORDER BY and SELECT) Expression (Before ORDER BY)
SettingQuotaAndLimits (Set limits and quota after reading from storage) SettingQuotaAndLimits (Set limits and quota after reading from storage)
ReadFromStorage (MergeTree with order) ReadFromStorage (MergeTree with order)
SELECT SELECT
......
...@@ -79,8 +79,15 @@ select number, quantileExact(number) over (partition by intDiv(number, 3)) q fro ...@@ -79,8 +79,15 @@ select number, quantileExact(number) over (partition by intDiv(number, 3)) q fro
9 9 9 9
select q * 10, quantileExact(number) over (partition by intDiv(number, 3)) q from numbers(10); -- { serverError 47 } select q * 10, quantileExact(number) over (partition by intDiv(number, 3)) q from numbers(10); -- { serverError 47 }
-- must work in WHERE if you wrap it in a subquery
select * from (select count(*) over () c from numbers(3)) where c > 0;
-- should work in ORDER BY -- should work in ORDER BY
1
2
3
select number, max(number) over (partition by intDiv(number, 3) order by number desc) m from numbers(10) order by m desc, number; select number, max(number) over (partition by intDiv(number, 3) order by number desc) m from numbers(10) order by m desc, number;
-- also works in ORDER BY if you wrap it in a subquery -- also works in ORDER BY if you wrap it in a subquery
...@@ -97,24 +104,35 @@ select number, max(number) over (partition by intDiv(number, 3) order by number ...@@ -97,24 +104,35 @@ select number, max(number) over (partition by intDiv(number, 3) order by number
2 2 2 2
select * from (select count(*) over () c from numbers(3)) order by c; select * from (select count(*) over () c from numbers(3)) order by c;
-- must work in WHERE if you wrap it in a subquery -- Example with window function only in ORDER BY. Here we make a rank of all
-- numbers sorted descending, and then sort by this rank descending, and must get
-- the ascending order.
1 1
2 2
3 3
select * from (select count(*) over () c from numbers(3)) where c > 0; select * from (select * from numbers(5) order by rand()) order by count() over (order by number desc) desc;
-- this one doesn't work yet -- looks like the column names clash, and the -- Aggregate functions as window function arguments. This query is semantically
-- window count() is overwritten with aggregate count() -- the same as the above one, only we replace `number` with
-- select number, count(), count() over (partition by intDiv(number, 3)) from numbers(10) group by number order by count() desc; -- `any(number) group by number` and so on.
0
1
2
3
4
select * from (select * from numbers(5) order by rand()) group by number order by sum(any(number)) over (order by min(number) desc) desc;
-- different windows -- different windows
-- an explain test would also be helpful, but it's too immature now and I don't -- an explain test would also be helpful, but it's too immature now and I don't
-- want to change reference all the time -- want to change reference all the time
1 1
0
2 2
3 3
4
select number, max(number) over (partition by intDiv(number, 3) order by number desc), count(number) over (partition by intDiv(number, 5) order by number) as m from numbers(31) order by number settings max_block_size = 2; select number, max(number) over (partition by intDiv(number, 3) order by number desc), count(number) over (partition by intDiv(number, 5) order by number) as m from numbers(31) order by number settings max_block_size = 2;
-- two functions over the same window -- two functions over the same window
......
...@@ -24,18 +24,24 @@ select number, quantileExact(number) over (partition by intDiv(number, 3)) q fro ...@@ -24,18 +24,24 @@ select number, quantileExact(number) over (partition by intDiv(number, 3)) q fro
-- last stage of select, after all other functions. -- 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 } select q * 10, quantileExact(number) over (partition by intDiv(number, 3)) q from numbers(10); -- { serverError 47 }
-- must work in WHERE if you wrap it in a subquery
select * from (select count(*) over () c from numbers(3)) where c > 0;
-- should work in ORDER BY -- should work in ORDER BY
select number, max(number) over (partition by intDiv(number, 3) order by number desc) m from numbers(10) order by m desc, number; select number, max(number) over (partition by intDiv(number, 3) order by number desc) m from numbers(10) order by m desc, number;
-- also works in ORDER BY if you wrap it in a subquery -- also works in ORDER BY if you wrap it in a subquery
select * from (select count(*) over () c from numbers(3)) order by c; select * from (select count(*) over () c from numbers(3)) order by c;
-- must work in WHERE if you wrap it in a subquery -- Example with window function only in ORDER BY. Here we make a rank of all
select * from (select count(*) over () c from numbers(3)) where c > 0; -- numbers sorted descending, and then sort by this rank descending, and must get
-- the ascending order.
select * from (select * from numbers(5) order by rand()) order by count() over (order by number desc) desc;
-- this one doesn't work yet -- looks like the column names clash, and the -- Aggregate functions as window function arguments. This query is semantically
-- window count() is overwritten with aggregate count() -- the same as the above one, only we replace `number` with
-- select number, count(), count() over (partition by intDiv(number, 3)) from numbers(10) group by number order by count() desc; -- `any(number) group by number` and so on.
select * from (select * from numbers(5) order by rand()) group by number order by sum(any(number)) over (order by min(number) desc) desc;
-- different windows -- different windows
-- an explain test would also be helpful, but it's too immature now and I don't -- an explain test would also be helpful, but it's too immature now and I don't
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册