From 7a04724b3c98374e2384e922d58115b4b1245329 Mon Sep 17 00:00:00 2001 From: feng lv Date: Mon, 4 Jan 2021 14:23:17 +0000 Subject: [PATCH] add select all syntax --- src/Parsers/ExpressionListParsers.cpp | 4 ++++ src/Parsers/ParserSelectQuery.cpp | 12 ++++++++++++ .../0_stateless/01632_select_all_syntax.reference | 7 +++++++ .../queries/0_stateless/01632_select_all_syntax.sql | 9 +++++++++ 4 files changed, 32 insertions(+) create mode 100644 tests/queries/0_stateless/01632_select_all_syntax.reference create mode 100644 tests/queries/0_stateless/01632_select_all_syntax.sql diff --git a/src/Parsers/ExpressionListParsers.cpp b/src/Parsers/ExpressionListParsers.cpp index f50cf71f54d..6e169e9135c 100644 --- a/src/Parsers/ExpressionListParsers.cpp +++ b/src/Parsers/ExpressionListParsers.cpp @@ -8,6 +8,7 @@ #include #include +#include namespace DB { @@ -86,6 +87,9 @@ bool ParserList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) auto parse_element = [&] { + ParserKeyword all("ALL"); + all.ignore(pos, expected); + ASTPtr element; if (!elem_parser->parse(pos, element, expected)) return false; diff --git a/src/Parsers/ParserSelectQuery.cpp b/src/Parsers/ParserSelectQuery.cpp index 91c48fc362d..b1c07a777c9 100644 --- a/src/Parsers/ParserSelectQuery.cpp +++ b/src/Parsers/ParserSelectQuery.cpp @@ -21,6 +21,7 @@ namespace ErrorCodes extern const int LIMIT_BY_WITH_TIES_IS_NOT_SUPPORTED; extern const int ROW_AND_ROWS_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; ParserKeyword s_select("SELECT"); + ParserKeyword s_all("ALL"); ParserKeyword s_distinct("DISTINCT"); ParserKeyword s_from("FROM"); 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 { + bool has_all = false; if (!s_select.ignore(pos, expected)) return false; + if (s_all.ignore(pos, expected)) + has_all = true; + if (s_distinct.ignore(pos, expected)) 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)) { ParserNumber num; diff --git a/tests/queries/0_stateless/01632_select_all_syntax.reference b/tests/queries/0_stateless/01632_select_all_syntax.reference new file mode 100644 index 00000000000..47c2a8c9b59 --- /dev/null +++ b/tests/queries/0_stateless/01632_select_all_syntax.reference @@ -0,0 +1,7 @@ +a +a +1 +1 +2 +45 +45 diff --git a/tests/queries/0_stateless/01632_select_all_syntax.sql b/tests/queries/0_stateless/01632_select_all_syntax.sql new file mode 100644 index 00000000000..9415f5ef0c7 --- /dev/null +++ b/tests/queries/0_stateless/01632_select_all_syntax.sql @@ -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);