fix formatting of LIMIT BY; add tests with remote() [#METR-23881]

This commit is contained in:
artpaul 2017-01-09 18:24:54 +05:00
parent d0961238b9
commit 79eb282eda
5 changed files with 16 additions and 7 deletions

View File

@ -1185,11 +1185,8 @@ void ExpressionAnalyzer::optimizeLimitBy()
for (const auto & elem : elems)
{
if (const auto id = typeid_cast<const ASTIdentifier*>(elem.get()))
{
if (elems_set.emplace(id->getColumnName()).second)
unique_elems.emplace_back(elem);
}
if (elems_set.emplace(elem->getColumnName()).second)
unique_elems.emplace_back(elem);
}
if (unique_elems.size() < elems.size())

View File

@ -1185,7 +1185,7 @@ void InterpreterSelectQuery::executePreLimit()
void InterpreterSelectQuery::executeLimitBy()
{
if (!query.limit_by_value)
if (!query.limit_by_value || !query.limit_by_expression_list)
return;
Names columns;

View File

@ -291,7 +291,9 @@ void ASTSelectQuery::formatImpl(const FormatSettings & s, FormatState & state, F
if (limit_by_value)
{
s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "LIMIT BY " << (s.hilite ? hilite_none : "");
s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "LIMIT " << (s.hilite ? hilite_none : "");
limit_by_value->formatImpl(s, state, frame);
s.ostr << (s.hilite ? hilite_keyword : "") << " BY " << (s.hilite ? hilite_none : "");
s.one_line
? limit_by_expression_list->formatImpl(s, state, frame)
: typeid_cast<const ASTExpressionList &>(*limit_by_expression_list).formatImplMultiline(s, state, frame);

View File

@ -15,3 +15,7 @@
1 John
3 Mary
4 Mary
0
0
0
1

View File

@ -23,4 +23,10 @@ SELECT Num, count(*) FROM test.limit_by GROUP BY Num ORDER BY Num LIMIT 2 BY Num
-- LIMIT BY can be combined with LIMIT
SELECT Num, Name FROM test.limit_by ORDER BY Num LIMIT 1 BY Num, Name LIMIT 3;
-- Distributed LIMIT BY
SELECT dummy FROM remote('127.0.0.{1,2}', system.one) LIMIT 1 BY dummy;
SELECT dummy FROM remote('127.0.0.{1,2}', system.one) LIMIT 2 BY dummy;
SELECT 1 as one FROM remote('127.0.0.{1,2}', system.one) LIMIT 1 BY one;
DROP TABLE IF EXISTS test.limit_by;