add select all syntax

This commit is contained in:
feng lv 2021-01-04 14:23:17 +00:00
parent 1e98917963
commit 7a04724b3c
4 changed files with 32 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <Parsers/parseIntervalKind.h> #include <Parsers/parseIntervalKind.h>
#include <Common/StringUtils/StringUtils.h> #include <Common/StringUtils/StringUtils.h>
#include <Parsers/CommonParsers.h>
namespace DB namespace DB
{ {
@ -86,6 +87,9 @@ bool ParserList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
auto parse_element = [&] auto parse_element = [&]
{ {
ParserKeyword all("ALL");
all.ignore(pos, expected);
ASTPtr element; ASTPtr element;
if (!elem_parser->parse(pos, element, expected)) if (!elem_parser->parse(pos, element, expected))
return false; return false;

View File

@ -21,6 +21,7 @@ namespace ErrorCodes
extern const int LIMIT_BY_WITH_TIES_IS_NOT_SUPPORTED; extern const int LIMIT_BY_WITH_TIES_IS_NOT_SUPPORTED;
extern const int ROW_AND_ROWS_TOGETHER; extern const int ROW_AND_ROWS_TOGETHER;
extern const int FIRST_AND_NEXT_TOGETHER; extern const int FIRST_AND_NEXT_TOGETHER;
extern const int LOGICAL_ERROR;
} }
@ -30,6 +31,7 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
node = select_query; node = select_query;
ParserKeyword s_select("SELECT"); ParserKeyword s_select("SELECT");
ParserKeyword s_all("ALL");
ParserKeyword s_distinct("DISTINCT"); ParserKeyword s_distinct("DISTINCT");
ParserKeyword s_from("FROM"); ParserKeyword s_from("FROM");
ParserKeyword s_prewhere("PREWHERE"); ParserKeyword s_prewhere("PREWHERE");
@ -93,12 +95,22 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
/// SELECT [DISTINCT] [TOP N [WITH TIES]] expr list /// SELECT [DISTINCT] [TOP N [WITH TIES]] expr list
{ {
bool has_all = false;
if (!s_select.ignore(pos, expected)) if (!s_select.ignore(pos, expected))
return false; return false;
if (s_all.ignore(pos, expected))
has_all = true;
if (s_distinct.ignore(pos, expected)) if (s_distinct.ignore(pos, expected))
select_query->distinct = true; select_query->distinct = true;
if (!has_all && s_all.ignore(pos, expected))
has_all = true;
if (has_all && select_query->distinct)
throw Exception("Can not use DISTINCT alongside ALL", ErrorCodes::LOGICAL_ERROR);
if (s_top.ignore(pos, expected)) if (s_top.ignore(pos, expected))
{ {
ParserNumber num; ParserNumber num;

View File

@ -0,0 +1,7 @@
a
a
1
1
2
45
45

View File

@ -0,0 +1,9 @@
SELECT ALL 'a';
SELECT DISTINCT 'a';
SELECT ALL * FROM (SELECT 1 UNION ALL SELECT 1);
SELECT DISTINCT * FROM (SELECT 2 UNION ALL SELECT 2);
SELECT ALL DISTINCT 1; -- { clientError 49 }
SELECT DISTINCT ALL 1; -- { clientError 49 }
SELECT sum(number) FROM numbers(10);
SELECT sum(ALL number) FROM numbers(10);