You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ji...@apache.org on 2017/10/05 22:03:33 UTC
[38/51] [abbrv] incubator-quickstep git commit: Add array expression
Add array expression
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/c9922f8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/c9922f8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/c9922f8e
Branch: refs/heads/new-op
Commit: c9922f8e18c8025f995bebd898cd99b5b91e82f3
Parents: 8a3b2cf
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Mon Oct 2 01:30:46 2017 -0500
Committer: Jianqiao Zhu <ji...@cs.wisc.edu>
Committed: Mon Oct 2 01:30:46 2017 -0500
----------------------------------------------------------------------
parser/ParseBasicExpressions.cpp | 27 +
parser/ParseBasicExpressions.hpp | 42 +
parser/ParseExpression.hpp | 1 +
parser/SqlLexer.lpp | 1 +
parser/SqlParser.ypp | 29 +
parser/preprocessed/SqlLexer_gen.cpp | 1429 ++++++------
parser/preprocessed/SqlLexer_gen.hpp | 2 +-
parser/preprocessed/SqlParser_gen.cpp | 3339 +++++++++++++++-------------
parser/preprocessed/SqlParser_gen.hpp | 115 +-
query_optimizer/resolver/Resolver.cpp | 28 +
query_optimizer/resolver/Resolver.hpp | 6 +
types/ArrayType.cpp | 2 +-
12 files changed, 2651 insertions(+), 2370 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c9922f8e/parser/ParseBasicExpressions.cpp
----------------------------------------------------------------------
diff --git a/parser/ParseBasicExpressions.cpp b/parser/ParseBasicExpressions.cpp
index 580cd09..fd9094c 100644
--- a/parser/ParseBasicExpressions.cpp
+++ b/parser/ParseBasicExpressions.cpp
@@ -127,4 +127,31 @@ void ParseFunctionCall::getFieldStringItems(
}
}
+std::string ParseArray::generateName() const {
+ string name("{");
+ if (!elements_.empty()) {
+ name.append(elements_.front()->generateName());
+ for (std::size_t i = 1; i < elements_.size(); ++i) {
+ name.append(",");
+ name.append(elements_.at(i)->generateName());
+ }
+ }
+ name.append("}");
+ return name;
+}
+
+void ParseArray::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 {
+ container_child_field_names->emplace_back("elements");
+ container_child_fields->emplace_back();
+ for (const auto &element : elements_) {
+ container_child_fields->back().emplace_back(element.get());
+ }
+}
+
} // namespace quickstep
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c9922f8e/parser/ParseBasicExpressions.hpp
----------------------------------------------------------------------
diff --git a/parser/ParseBasicExpressions.hpp b/parser/ParseBasicExpressions.hpp
index 4572214..af2393f 100644
--- a/parser/ParseBasicExpressions.hpp
+++ b/parser/ParseBasicExpressions.hpp
@@ -344,6 +344,48 @@ class ParseFunctionCall : public ParseExpression {
DISALLOW_COPY_AND_ASSIGN(ParseFunctionCall);
};
+
+class ParseArray : public ParseExpression {
+ public:
+ ParseArray(const int line_number, const int column_number)
+ : ParseExpression(line_number, column_number) {}
+
+ ~ParseArray() override {
+ }
+
+ ExpressionType getExpressionType() const override {
+ return kArray;
+ }
+
+ std::string getName() const override {
+ return "Array";
+ }
+
+ std::string generateName() const override;
+
+ const std::vector<std::unique_ptr<ParseExpression>>& elements() const {
+ return elements_;
+ }
+
+ void add(ParseExpression *element) {
+ elements_.emplace_back(std::unique_ptr<ParseExpression>(element));
+ }
+
+ 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;
+
+ private:
+ std::vector<std::unique_ptr<ParseExpression>> elements_;
+
+ DISALLOW_COPY_AND_ASSIGN(ParseArray);
+};
+
/** @} */
} // namespace quickstep
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c9922f8e/parser/ParseExpression.hpp
----------------------------------------------------------------------
diff --git a/parser/ParseExpression.hpp b/parser/ParseExpression.hpp
index 94b4487..f9a33a2 100644
--- a/parser/ParseExpression.hpp
+++ b/parser/ParseExpression.hpp
@@ -37,6 +37,7 @@ namespace quickstep {
class ParseExpression : public ParseTreeNode {
public:
enum ExpressionType {
+ kArray,
kAttribute,
kBinaryExpression,
kFunctionCall,
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c9922f8e/parser/SqlLexer.lpp
----------------------------------------------------------------------
diff --git a/parser/SqlLexer.lpp b/parser/SqlLexer.lpp
index 9a63483..b45d8ab 100644
--- a/parser/SqlLexer.lpp
+++ b/parser/SqlLexer.lpp
@@ -39,6 +39,7 @@ namespace quickstep {
class BinaryOperation;
class Comparison;
+class ParseArray;
class ParseAssignment;
class ParseAttribute;
class ParseAttributeDefinition;
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c9922f8e/parser/SqlParser.ypp
----------------------------------------------------------------------
diff --git a/parser/SqlParser.ypp b/parser/SqlParser.ypp
index 156e9e7..01be345 100644
--- a/parser/SqlParser.ypp
+++ b/parser/SqlParser.ypp
@@ -186,6 +186,7 @@ typedef void* yyscan_t;
quickstep::ParseString *unary_operation_;
quickstep::ParseString *binary_operation_;
+ quickstep::ParseArray *array_expression_;
quickstep::ParseFunctionCall *function_call_;
quickstep::PtrList<quickstep::ParseExpression> *expression_list_;
@@ -396,6 +397,11 @@ void NotSupported(const YYLTYPE *location, yyscan_t yyscanner, const std::string
extract_function
substr_function
+
+%type <array_expression_>
+ array_expression
+ array_element_commalist
+
%type <attribute_>
attribute_ref
@@ -1710,6 +1716,9 @@ expression_base:
| literal_value {
$$ = new quickstep::ParseScalarLiteral($1);
}
+ | array_expression {
+ $$ = $1;
+ }
| function_call {
$$ = $1;
}
@@ -1740,6 +1749,26 @@ expression_base:
$$ = $1;
};
+array_expression:
+ array_element_commalist TOKEN_RBRACE {
+ $$ = $1;
+ }
+ | TOKEN_LBRACE TOKEN_RBRACE {
+ $$ = new quickstep::ParseArray(@1.first_line, @1.first_column);
+ }
+ ;
+
+array_element_commalist:
+ array_element_commalist ',' add_expression {
+ $$ = $1;
+ $$->add($3);
+ }
+ | TOKEN_LBRACE add_expression {
+ $$ = new quickstep::ParseArray(@1.first_line, @1.first_column);
+ $$->add($2);
+ }
+ ;
+
function_call:
any_name '(' ')' {
$$ = new quickstep::ParseFunctionCall(