update syntax and test

This commit is contained in:
CurtizJ 2018-08-27 19:43:29 +03:00
parent b48a144d78
commit 0e28195e7a
3 changed files with 26 additions and 13 deletions

View File

@ -1,5 +1,4 @@
#include <memory>
#include <Poco/String.h>
#include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/IParserBase.h>
@ -134,22 +133,24 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
const String identifier_totals = "identifier_totals";
const String identifier_rollup = "identifier_rollup";
/// WITH TOTALS and/or ROLLUP
/// WITH ROLLUP
if (s_with.ignore(pos, expected))
{
if (!exp_list.parse(pos, totals_and_rollup_list, expected))
return false;
for (const auto & child : totals_and_rollup_list->children)
{
String id = Poco::toLower(child->getID());
if (id == identifier_totals)
select_query->group_by_with_totals = true;
else if (id == identifier_rollup)
if (s_rollup.ignore(pos, expected))
select_query->group_by_with_rollup = true;
else if (s_totals.ignore(pos, expected))
select_query->group_by_with_totals = true;
else
return false;
}
/// WITH TOTALS
if (s_with.ignore(pos, expected))
{
if (select_query->group_by_with_totals || !s_totals.ignore(pos, expected))
return false;
select_query->group_by_with_totals = true;
}
/// HAVING expr

View File

@ -17,3 +17,11 @@ b 2 35 2
120 8
a 70 4
b 50 4
120 8
a 70 4
b 50 4
120 8
a 70 4
b 50 4
120 8

View File

@ -15,3 +15,7 @@ SELECT a, b, sum(s), count() from test.rollup GROUP BY ROLLUP(a, b) ORDER BY a,
SELECT a, b, sum(s), count() from test.rollup GROUP BY ROLLUP(a, b) WITH TOTALS ORDER BY a, b;
SELECT a, sum(s), count() from test.rollup GROUP BY ROLLUP(a) ORDER BY a;
SELECT a, sum(s), count() from test.rollup GROUP BY a WITH ROLLUP ORDER BY a;
SELECT a, sum(s), count() from test.rollup GROUP BY a WITH ROLLUP WITH TOTALS ORDER BY a;