/src/duckdb/src/main/relation/join_relation.cpp
Line | Count | Source |
1 | | #include "duckdb/main/relation/join_relation.hpp" |
2 | | #include "duckdb/main/client_context.hpp" |
3 | | #include "duckdb/parser/query_node/select_node.hpp" |
4 | | #include "duckdb/parser/expression/star_expression.hpp" |
5 | | #include "duckdb/parser/tableref/joinref.hpp" |
6 | | #include "duckdb/common/enum_util.hpp" |
7 | | #include "duckdb/main/client_context_wrapper.hpp" |
8 | | |
9 | | namespace duckdb { |
10 | | |
11 | | JoinRelation::JoinRelation(shared_ptr<Relation> left_p, shared_ptr<Relation> right_p, |
12 | | unique_ptr<ParsedExpression> condition_p, JoinType type, JoinRefType join_ref_type) |
13 | 0 | : Relation(left_p->context, RelationType::JOIN_RELATION), left(std::move(left_p)), right(std::move(right_p)), |
14 | 0 | condition(std::move(condition_p)), join_type(type), join_ref_type(join_ref_type) { |
15 | 0 | if (left->context->GetContext() != right->context->GetContext()) { |
16 | 0 | throw InvalidInputException("Cannot combine LEFT and RIGHT relations of different connections!"); |
17 | 0 | } |
18 | 0 | TryBindRelation(columns); |
19 | 0 | } |
20 | | |
21 | | JoinRelation::JoinRelation(shared_ptr<Relation> left_p, shared_ptr<Relation> right_p, vector<string> using_columns_p, |
22 | | JoinType type, JoinRefType join_ref_type) |
23 | 0 | : Relation(left_p->context, RelationType::JOIN_RELATION), left(std::move(left_p)), right(std::move(right_p)), |
24 | 0 | using_columns(std::move(using_columns_p)), join_type(type), join_ref_type(join_ref_type) { |
25 | 0 | if (left->context->GetContext() != right->context->GetContext()) { |
26 | 0 | throw InvalidInputException("Cannot combine LEFT and RIGHT relations of different connections!"); |
27 | 0 | } |
28 | 0 | TryBindRelation(columns); |
29 | 0 | } |
30 | | |
31 | 0 | unique_ptr<QueryNode> JoinRelation::GetQueryNode() { |
32 | 0 | auto result = make_uniq<SelectNode>(); |
33 | 0 | result->select_list.push_back(make_uniq<StarExpression>()); |
34 | 0 | result->from_table = GetTableRef(); |
35 | 0 | return std::move(result); |
36 | 0 | } |
37 | | |
38 | 0 | unique_ptr<TableRef> JoinRelation::GetTableRef() { |
39 | 0 | auto join_ref = make_uniq<JoinRef>(join_ref_type); |
40 | 0 | join_ref->left = left->GetTableRef(); |
41 | 0 | join_ref->right = right->GetTableRef(); |
42 | 0 | if (condition) { |
43 | 0 | join_ref->condition = condition->Copy(); |
44 | 0 | } |
45 | 0 | join_ref->using_columns = using_columns; |
46 | 0 | join_ref->type = join_type; |
47 | 0 | join_ref->delim_flipped = delim_flipped; |
48 | 0 | for (auto &col : duplicate_eliminated_columns) { |
49 | 0 | join_ref->duplicate_eliminated_columns.emplace_back(col->Copy()); |
50 | 0 | } |
51 | 0 | return std::move(join_ref); |
52 | 0 | } |
53 | | |
54 | 0 | const vector<ColumnDefinition> &JoinRelation::Columns() { |
55 | 0 | return this->columns; |
56 | 0 | } |
57 | | |
58 | 0 | string JoinRelation::ToString(idx_t depth) { |
59 | 0 | string str = RenderWhitespace(depth); |
60 | 0 | str += "Join " + EnumUtil::ToString(join_ref_type) + " " + EnumUtil::ToString(join_type); |
61 | 0 | if (condition) { |
62 | 0 | str += " " + condition->GetName(); |
63 | 0 | } |
64 | |
|
65 | 0 | return str + "\n" + left->ToString(depth + 1) + "\n" + right->ToString(depth + 1); |
66 | 0 | } |
67 | | |
68 | | } // namespace duckdb |