From b2961bcc31450f75b249d512bfde7150e1397712 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 22 Jul 2019 00:19:42 +0300 Subject: [PATCH] Added check for empty number of columns; improved test --- dbms/src/Interpreters/SyntaxAnalyzer.cpp | 5 +++++ .../00969_columns_clause.reference | 22 +++++++++++++++++++ .../0_stateless/00969_columns_clause.sql | 20 +++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/dbms/src/Interpreters/SyntaxAnalyzer.cpp b/dbms/src/Interpreters/SyntaxAnalyzer.cpp index 62982ea1e59..83cacc94692 100644 --- a/dbms/src/Interpreters/SyntaxAnalyzer.cpp +++ b/dbms/src/Interpreters/SyntaxAnalyzer.cpp @@ -41,6 +41,7 @@ namespace ErrorCodes extern const int EMPTY_NESTED_TABLE; extern const int LOGICAL_ERROR; extern const int INVALID_JOIN_ON_EXPRESSION; + extern const int EMPTY_LIST_OF_COLUMNS_QUERIED; } NameSet removeDuplicateColumns(NamesAndTypesList & columns) @@ -110,6 +111,10 @@ void translateQualifiedNames(ASTPtr & query, const ASTSelectQuery & select_query TranslateQualifiedNamesVisitor::Data visitor_data(source_columns_set, tables_with_columns); TranslateQualifiedNamesVisitor visitor(visitor_data, log.stream()); visitor.visit(query); + + /// This may happen after expansion of COLUMNS('regexp'). + if (select_query.select()->children.empty()) + throw Exception("Empty list of columns in SELECT query", ErrorCodes::EMPTY_LIST_OF_COLUMNS_QUERIED); } bool hasArrayJoin(const ASTPtr & ast) diff --git a/dbms/tests/queries/0_stateless/00969_columns_clause.reference b/dbms/tests/queries/0_stateless/00969_columns_clause.reference index fcfd7d0919e..125a49fae0d 100644 --- a/dbms/tests/queries/0_stateless/00969_columns_clause.reference +++ b/dbms/tests/queries/0_stateless/00969_columns_clause.reference @@ -1,2 +1,24 @@ 100 10 120 8 +0 0 +1 1 +0 0 +1 1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +2 +3 +2 +4 +3 diff --git a/dbms/tests/queries/0_stateless/00969_columns_clause.sql b/dbms/tests/queries/0_stateless/00969_columns_clause.sql index 1ea344f0bcd..fc5b72d3913 100644 --- a/dbms/tests/queries/0_stateless/00969_columns_clause.sql +++ b/dbms/tests/queries/0_stateless/00969_columns_clause.sql @@ -5,3 +5,23 @@ INSERT INTO ColumnsClauseTest VALUES (100, 10, 324), (120, 8, 23); SELECT COLUMNS('product.*') from ColumnsClauseTest ORDER BY product_price; DROP TABLE ColumnsClauseTest; + +SELECT number, COLUMNS('') FROM numbers(2); +SELECT number, COLUMNS('ber') FROM numbers(2); -- It works for unanchored regular expressions. +SELECT number, COLUMNS('x') FROM numbers(2); +SELECT COLUMNS('') FROM numbers(2); + +SELECT COLUMNS('x') FROM numbers(10) WHERE number > 5; -- { serverError 51 } + +SELECT * FROM numbers(2) WHERE NOT ignore(); +SELECT * FROM numbers(2) WHERE NOT ignore(*); +SELECT * FROM numbers(2) WHERE NOT ignore(COLUMNS('.+')); +SELECT * FROM numbers(2) WHERE NOT ignore(COLUMNS('x')); +SELECT COLUMNS('n') + COLUMNS('u') FROM system.numbers LIMIT 2; + +SELECT COLUMNS('n') + COLUMNS('u') FROM (SELECT 1 AS a, 2 AS b); -- { serverError 42 } +SELECT COLUMNS('a') + COLUMNS('b') FROM (SELECT 1 AS a, 2 AS b); +SELECT COLUMNS('a') + COLUMNS('a') FROM (SELECT 1 AS a, 2 AS b); +SELECT COLUMNS('b') + COLUMNS('b') FROM (SELECT 1 AS a, 2 AS b); +SELECT COLUMNS('a|b') + COLUMNS('b') FROM (SELECT 1 AS a, 2 AS b); -- { serverError 42 } +SELECT plus(COLUMNS('^(a|b)$')) FROM (SELECT 1 AS a, 2 AS b);