1#include "duckdb/main/relation/setop_relation.hpp"
2#include "duckdb/main/client_context.hpp"
3#include "duckdb/parser/query_node/set_operation_node.hpp"
4
5namespace duckdb {
6
7SetOpRelation::SetOpRelation(shared_ptr<Relation> left_p, shared_ptr<Relation> right_p, SetOperationType setop_type_p)
8 : Relation(left_p->context, RelationType::SET_OPERATION_RELATION), left(move(left_p)), right(move(right_p)),
9 setop_type(setop_type_p) {
10 if (&left->context != &right->context) {
11 throw Exception("Cannot combine LEFT and RIGHT relations of different connections!");
12 }
13 vector<ColumnDefinition> dummy_columns;
14 context.TryBindRelation(*this, dummy_columns);
15}
16
17unique_ptr<QueryNode> SetOpRelation::GetQueryNode() {
18 auto result = make_unique<SetOperationNode>();
19 result->left = left->GetQueryNode();
20 result->right = right->GetQueryNode();
21 result->setop_type = setop_type;
22 return move(result);
23}
24
25string SetOpRelation::GetAlias() {
26 return left->GetAlias();
27}
28
29const vector<ColumnDefinition> &SetOpRelation::Columns() {
30 return left->Columns();
31}
32
33string SetOpRelation::ToString(idx_t depth) {
34 string str = RenderWhitespace(depth);
35 switch (setop_type) {
36 case SetOperationType::UNION:
37 str += "Union";
38 break;
39 case SetOperationType::EXCEPT:
40 str += "Except";
41 break;
42 case SetOperationType::INTERSECT:
43 str += "Intersect";
44 break;
45 default:
46 throw Exception("Unknown setop type");
47 }
48 return str + "\n" + left->ToString(depth + 1) + right->ToString(depth + 1);
49}
50
51} // namespace duckdb
52