Implement parser and resolver for UNION and INTERSECT operators #229
Conversation
parser/ParseSetOperation.hpp
Outdated
* @brief The possible types of set operations. | ||
*/ | ||
enum SetOperationType { | ||
kIntersect, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to kIntersect = 0,
.
parser/ParseSetOperation.hpp
Outdated
case kSingle: | ||
return "Single"; | ||
default: | ||
return "Unknown"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to change to LOG(FATAL) << "Unknown set operation type.";
.
parser/ParseSetOperation.hpp
Outdated
|
||
private: | ||
PtrList<ParseTreeNode> operands_; | ||
SetOperationType set_operation_type_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mark as const
.
parser/ParseSetOperation.hpp
Outdated
*/ | ||
enum SetOperationType { | ||
kIntersect, | ||
kSingle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: does kSingle
has an extra meaning beyond representing a SELECT
query?
parser/ParseStatement.hpp
Outdated
@@ -479,49 +480,49 @@ class ParseStatementDropTable : public ParseStatement { | |||
}; | |||
|
|||
/** | |||
* @brief The parsed representation of a SELECT statement. | |||
* @brief The parsed representation of a UNION/INTERSECT/SELECT statement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: a
to an
.
<< "and " << possible_type.getName(); | ||
} | ||
} else { | ||
THROW_SQL_ERROR_AT(&parse_set_operations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce to two-whitespace-indentation.
// Get the possible output attributes that the attributes of all operands can cast to. | ||
std::vector<E::AttributeReferencePtr> possible_attributes; | ||
for (std::size_t aid = 0; aid < operation_attributes.size(); ++aid) { | ||
E::AttributeReferencePtr possible_attribute = attribute_matrix[0][aid]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark const
?
E::AttributeReference::Create(context_->nextExprId(), | ||
attr->attribute_name(), | ||
attr->attribute_alias(), | ||
""/* relation_name*/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to "" /* relation_name */,
/** | ||
* @brief Resolves a set operation and returns a logical plan. | ||
*/ | ||
logical::LogicalPtr resolveSetOperationDispatcher( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming to resolveSetOperation
?
L::SetOperation::kUnionAll, resolved_operations, output_attributes); | ||
default: | ||
LOG(FATAL) << "Unknown operation: " << parse_set_operations.toString(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add return nullptr;
to fix the error in Travis CI.
@@ -676,7 +686,7 @@ sql_statement: | |||
| quit_statement { | |||
$$ = $1; | |||
} | |||
| select_statement { | |||
| set_operation_statement { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we add set_operation_statement
, while still keeping select_statement
so that we don't need to modify test files with SELECT
-only queries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will lead to a conflict -- the parser cannot decide whether a SELECT
query should be reduced to a select statement or a set operation statement.
LGTM! Merging. |
@jianqiao We need to wait for squashing commits into one before merge. |
6750cae
to
ec877c6
Compare
ec877c6
to
5b7b5cb
Compare
$$ = new quickstep::ParseSetOperation(@1.first_line, @1.first_column, quickstep::ParseSetOperation::kSelect); | ||
$$->addOperand($1); | ||
} | ||
|
||
select_query: | ||
TOKEN_SELECT opt_all_distinct selection from_clause opt_where_clause opt_group_by_clause opt_having_clause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I observed the following warning:
SqlParser.ypp:1243.16-31: warning: unused value: $2 [-Wother]
TOKEN_SELECT opt_all_distinct selection from_clause opt_where_clause opt_group_by_clause opt_having_clause
^^^^^^^^^^^^^^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from the original ypp file, since we do not implement the select query like 'SELECT ALL ...' or 'SELECT DISTINCT ...'
This pull request implements the parser and resolver parts of set operations (
UNION
andINTERSECT
).It also supports composite set operations, e.g.
Note: will add parser and resolver tests, so do not merge yet.