Added PRIORITY clause in parser. - SQL statements (right now only SELECT statements) support "WITH PRIORITY N" clause. - The priority value should be a non-zero unsigned integer. - The priority value is a part of the QueryHandle class.
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/d6428914 Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/d6428914 Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/d6428914 Branch: refs/heads/adaptive-bloom-filters Commit: d64289148bee499e2232637602b4197da6791fc4 Parents: 07435a4 Author: Harshad Deshmukh <hbdeshm...@apache.org> Authored: Fri Jun 17 16:01:19 2016 -0500 Committer: Harshad Deshmukh <hbdeshm...@apache.org> Committed: Mon Jun 20 12:30:20 2016 -0500 ---------------------------------------------------------------------- parser/CMakeLists.txt | 8 + parser/ParsePriority.hpp | 94 + parser/ParseStatement.hpp | 33 +- parser/SqlLexer.lpp | 2 + parser/SqlParser.ypp | 37 +- parser/preprocessed/SqlLexer_gen.cpp | 1263 +++--- parser/preprocessed/SqlLexer_gen.hpp | 16 +- parser/preprocessed/SqlParser_gen.cpp | 5699 +++++++++++++++------------- parser/preprocessed/SqlParser_gen.hpp | 323 +- parser/tests/Select.test | 43 + query_optimizer/QueryHandle.hpp | 13 +- query_optimizer/QueryProcessor.cpp | 4 +- 12 files changed, 4120 insertions(+), 3415 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d6428914/parser/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/parser/CMakeLists.txt b/parser/CMakeLists.txt index 114ad14..32ea1a9 100644 --- a/parser/CMakeLists.txt +++ b/parser/CMakeLists.txt @@ -103,6 +103,7 @@ add_library(quickstep_parser_ParsePartitionClause ../empty_src.cpp ParsePartitio add_library(quickstep_parser_ParsePredicate ParsePredicate.cpp ParsePredicate.hpp) add_library(quickstep_parser_ParsePredicateExists ../empty_src.cpp ParsePredicateExists.hpp) add_library(quickstep_parser_ParsePredicateInTableQuery ../empty_src.cpp ParsePredicateInTableQuery.hpp) +add_library(quickstep_parser_ParsePriority ../empty_src.cpp ParsePriority.hpp) add_library(quickstep_parser_ParseSample ParseSample.cpp ParseSample.hpp) add_library(quickstep_parser_ParseSelect ../empty_src.cpp ParseSelect.hpp) add_library(quickstep_parser_ParseSelectionClause ParseSelectionClause.cpp ParseSelectionClause.hpp) @@ -229,6 +230,10 @@ target_link_libraries(quickstep_parser_ParsePredicateInTableQuery quickstep_parser_ParsePredicate quickstep_parser_ParseSubqueryExpression quickstep_utility_Macros) +target_link_libraries(quickstep_parser_ParsePriority + quickstep_parser_ParseLiteralValue + quickstep_parser_ParseTreeNode + quickstep_utility_Macros) target_link_libraries(quickstep_parser_ParseSample quickstep_parser_ParseLiteralValue quickstep_parser_ParseTreeNode @@ -267,6 +272,7 @@ target_link_libraries(quickstep_parser_ParseStatement quickstep_parser_ParseKeyValue quickstep_parser_ParsePartitionClause quickstep_parser_ParsePredicate + quickstep_parser_ParsePriority quickstep_parser_ParseSelect quickstep_parser_ParseString quickstep_parser_ParseSubqueryTableReference @@ -337,6 +343,7 @@ target_link_libraries(quickstep_parser_SqlParser quickstep_parser_ParsePredicate quickstep_parser_ParsePredicateExists quickstep_parser_ParsePredicateInTableQuery + quickstep_parser_ParsePriority quickstep_parser_ParseSample quickstep_parser_ParseSelect quickstep_parser_ParseSelectionClause @@ -414,6 +421,7 @@ target_link_libraries(quickstep_parser quickstep_parser_ParsePredicate quickstep_parser_ParsePredicateExists quickstep_parser_ParsePredicateInTableQuery + quickstep_parser_ParsePriority quickstep_parser_ParserUtil quickstep_parser_ParseSample quickstep_parser_ParseSelect http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d6428914/parser/ParsePriority.hpp ---------------------------------------------------------------------- diff --git a/parser/ParsePriority.hpp b/parser/ParsePriority.hpp new file mode 100644 index 0000000..89806d4 --- /dev/null +++ b/parser/ParsePriority.hpp @@ -0,0 +1,94 @@ +/** + * Copyright 2016, Quickstep Research Group, Computer Sciences Department, + * University of WisconsinâMadison. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +#ifndef QUICKSTEP_PARSER_PARSE_PRIORITY_HPP_ +#define QUICKSTEP_PARSER_PARSE_PRIORITY_HPP_ + +#include <memory> +#include <string> +#include <vector> + +#include "parser/ParseLiteralValue.hpp" +#include "parser/ParseTreeNode.hpp" +#include "utility/Macros.hpp" + +namespace quickstep { + +/** \addtogroup Parser + * @{ + */ + +/** + * @brief A parsed representation of PRIORITY. + **/ +class ParsePriority : public ParseTreeNode { + public: + /** + * @brief Constructor. + * + * @param line_number The line number of "PRIORITY" in the SQL statement. + * @param column_number The column number of "PRIORITY" in the SQL statement. + * @param priority_expression The PRIORITY value expression. + **/ + ParsePriority(const int line_number, + const int column_number, + NumericParseLiteralValue *priority_expression) + : ParseTreeNode(line_number, column_number), + priority_expression_(priority_expression) {} + + /** + * @brief Destructor. + */ + ~ParsePriority() override {} + + /** + * @brief Gets the PRIORITY expression. + * + * @return PRIORITY expression + */ + const NumericParseLiteralValue* priority_expression() const { + return priority_expression_.get(); + } + + std::string getName() const override { + return "PRIORITY"; + } + + protected: + void getFieldStringItems( + std::vector<std::string> *inline_field_names, + std::vector<std::string> *inline_field_values, + std::vector<std::string> *non_container_child_field_names, + std::vector<const ParseTreeNode *> *non_container_child_fields, + std::vector<std::string> *container_child_field_names, + std::vector<std::vector<const ParseTreeNode *>> *container_child_fields) + const override { + non_container_child_field_names->push_back(""); + non_container_child_fields->push_back(priority_expression_.get()); + } + + private: + std::unique_ptr<NumericParseLiteralValue> priority_expression_; + + DISALLOW_COPY_AND_ASSIGN(ParsePriority); +}; + +/** @} */ + +} // namespace quickstep + +#endif // QUICKSTEP_PARSER_PARSE_PRIORITY_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d6428914/parser/ParseStatement.hpp ---------------------------------------------------------------------- diff --git a/parser/ParseStatement.hpp b/parser/ParseStatement.hpp index 65acc68..61475a9 100644 --- a/parser/ParseStatement.hpp +++ b/parser/ParseStatement.hpp @@ -32,6 +32,7 @@ #include "parser/ParseKeyValue.hpp" #include "parser/ParsePartitionClause.hpp" #include "parser/ParsePredicate.hpp" +#include "parser/ParsePriority.hpp" #include "parser/ParseSelect.hpp" #include "parser/ParseString.hpp" #include "parser/ParseSubqueryTableReference.hpp" @@ -83,6 +84,16 @@ class ParseStatement : public ParseTreeNode { **/ virtual StatementType getStatementType() const = 0; + /** + * @brief Get the priority of the SQL statement. Note that the priority is + * an unsigned non-zero integer. + * + * @return The priority of the SQL statement. The default priority is 1. + **/ + virtual const std::uint64_t getPriority() const { + return 1; + } + protected: ParseStatement(const int line_number, const int column_number) : ParseTreeNode(line_number, column_number) { @@ -480,14 +491,18 @@ class ParseStatementSelect : public ParseStatement { * @param column_number Column number of the first token of this node in the SQL statement. * @param select_query The top-level SELECT query. * @param with_clause The WITH clause of common table query expressions. + * @param priority_clause The PRIORITY clause of this query. If not valid or + * not present, this is NULL. **/ ParseStatementSelect(const int line_number, const int column_number, ParseSelect *select_query, - PtrVector<ParseSubqueryTableReference> *with_clause) + PtrVector<ParseSubqueryTableReference> *with_clause, + ParsePriority *priority_clause) : ParseStatement(line_number, column_number), select_query_(select_query), - with_clause_(with_clause) { + with_clause_(with_clause), + priority_clause_(priority_clause) { } /** @@ -518,6 +533,14 @@ class ParseStatementSelect : public ParseStatement { return with_clause_.get(); } + const std::uint64_t getPriority() const override { + if (priority_clause_ != nullptr) { + DCHECK(priority_clause_->priority_expression() != nullptr); + return priority_clause_->priority_expression()->long_value(); + } + return 1; + } + protected: void getFieldStringItems( std::vector<std::string> *inline_field_names, @@ -536,11 +559,17 @@ class ParseStatementSelect : public ParseStatement { container_child_fields->back().push_back(&common_subquery); } } + + if (priority_clause_ != nullptr) { + non_container_child_field_names->push_back("priority"); + non_container_child_fields->push_back(priority_clause_.get()); + } } private: std::unique_ptr<ParseSelect> select_query_; std::unique_ptr<PtrVector<ParseSubqueryTableReference>> with_clause_; + std::unique_ptr<ParsePriority> priority_clause_; DISALLOW_COPY_AND_ASSIGN(ParseStatementSelect); }; http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d6428914/parser/SqlLexer.lpp ---------------------------------------------------------------------- diff --git a/parser/SqlLexer.lpp b/parser/SqlLexer.lpp index ee34400..ec18f38 100644 --- a/parser/SqlLexer.lpp +++ b/parser/SqlLexer.lpp @@ -61,6 +61,7 @@ class ParseOrderBy; class ParseOrderByItem; class ParsePartitionClause; class ParsePredicate; +class ParsePriority; class ParseSample; class ParseScalarLiteral; class ParseSearchedWhenClause; @@ -253,6 +254,7 @@ unsigned_numeric_literal {exact_numeric_literal}|{approximate_numeric_literal} "percent" return TOKEN_PERCENT; "preceding" return TOKEN_PRECEDING; "primary" return TOKEN_PRIMARY; + "priority" return TOKEN_PRIORITY; "quit" return TOKEN_QUIT; "range" return TOKEN_RANGE; "real" return TOKEN_REAL; http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/d6428914/parser/SqlParser.ypp ---------------------------------------------------------------------- diff --git a/parser/SqlParser.ypp b/parser/SqlParser.ypp index 81fa3ae..382ea44 100644 --- a/parser/SqlParser.ypp +++ b/parser/SqlParser.ypp @@ -85,6 +85,7 @@ typedef struct YYLTYPE { #include "parser/ParsePredicate.hpp" #include "parser/ParsePredicateExists.hpp" #include "parser/ParsePredicateInTableQuery.hpp" +#include "parser/ParsePriority.hpp" #include "parser/ParserUtil.hpp" #include "parser/ParseSample.hpp" #include "parser/ParseSelect.hpp" @@ -212,6 +213,8 @@ typedef void* yyscan_t; quickstep::PtrVector<quickstep::ParseSubqueryTableReference> *with_list_; quickstep::ParseSubqueryTableReference *with_list_element_; + + quickstep::ParsePriority *opt_priority_clause_; } %{ @@ -319,6 +322,7 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %token TOKEN_PERCENT; %token TOKEN_PRECEDING; %token TOKEN_PRIMARY; +%token TOKEN_PRIORITY; %token TOKEN_QUIT; %token TOKEN_RANGE; %token TOKEN_REAL; @@ -583,6 +587,9 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string %type <window_frame_info_> opt_window_frame +%type <opt_priority_clause_> + opt_priority_clause + %type <with_list_> with_clause with_list @@ -1143,13 +1150,35 @@ assignment_item: /* Select Queries */ select_statement: - select_query { - $$ = new quickstep::ParseStatementSelect(@1.first_line, @1.first_column, $1, nullptr); + select_query opt_priority_clause { + $$ = new quickstep::ParseStatementSelect(@1.first_line, @1.first_column, $1, nullptr, $2); } - | with_clause select_query { - $$ = new quickstep::ParseStatementSelect(@1.first_line, @1.first_column, $2, $1); + | with_clause select_query opt_priority_clause { + $$ = new quickstep::ParseStatementSelect(@1.first_line, @1.first_column, $2, $1, $3); }; +opt_priority_clause: + { + $$ = nullptr; + } + | TOKEN_WITH TOKEN_PRIORITY TOKEN_UNSIGNED_NUMVAL { + if ($3->float_like()) { + delete $3; + $$ = nullptr; + quickstep_yyerror(&@3, yyscanner, nullptr, "PRIORITY value must be an integer"); + YYERROR; + } else { + if ($3->long_value() <= 0) { + delete $3; + $$ = nullptr; + quickstep_yyerror(&@3, yyscanner, nullptr, "PRIORITY value must be positive"); + YYERROR; + } else { + $$ = new quickstep::ParsePriority(@1.first_line, @1.first_column, $3); + } + } + }; + with_clause: TOKEN_WITH with_list { $$ = $2;