MCPcopy Create free account
hub / github.com/apache/arrow / DoHashJoin

Function DoHashJoin

cpp/examples/arrow/join_example.cc:84–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84arrow::Status DoHashJoin() {
85 ARROW_RETURN_NOT_OK(arrow::compute::Initialize());
86 arrow::dataset::internal::Initialize();
87
88 ARROW_ASSIGN_OR_RAISE(auto l_dataset, CreateDataSetFromCSVData(true));
89 ARROW_ASSIGN_OR_RAISE(auto r_dataset, CreateDataSetFromCSVData(false));
90
91 auto l_options = std::make_shared<arrow::dataset::ScanOptions>();
92 // create empty projection: "default" projection where each field is mapped to a
93 // field_ref
94 l_options->projection = cp::project({}, {});
95
96 auto r_options = std::make_shared<arrow::dataset::ScanOptions>();
97 // create empty projection: "default" projection where each field is mapped to a
98 // field_ref
99 r_options->projection = cp::project({}, {});
100
101 // construct the scan node
102 auto l_scan_node_options = arrow::dataset::ScanNodeOptions{l_dataset, l_options};
103 auto r_scan_node_options = arrow::dataset::ScanNodeOptions{r_dataset, r_options};
104
105 arrow::acero::Declaration left{"scan", std::move(l_scan_node_options)};
106 arrow::acero::Declaration right{"scan", std::move(r_scan_node_options)};
107
108 arrow::acero::HashJoinNodeOptions join_opts{arrow::acero::JoinType::INNER,
109 /*in_left_keys=*/{"lkey"},
110 /*in_right_keys=*/{"rkey"},
111 /*filter*/ arrow::compute::literal(true),
112 /*output_suffix_for_left*/ "_l",
113 /*output_suffix_for_right*/ "_r"};
114
115 arrow::acero::Declaration hashjoin{
116 "hashjoin", {std::move(left), std::move(right)}, join_opts};
117
118 // expected columns l_a, l_b
119 ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::Table> response_table,
120 arrow::acero::DeclarationToTable(std::move(hashjoin)));
121
122 std::cout << "Results : " << response_table->ToString() << std::endl;
123
124 return arrow::Status::OK();
125}
126
127int main(int argc, char** argv) {
128 auto status = DoHashJoin();

Callers 1

mainFunction · 0.85

Calls 7

projectFunction · 0.85
DeclarationToTableFunction · 0.85
ARROW_ASSIGN_OR_RAISEFunction · 0.70
InitializeFunction · 0.50
literalFunction · 0.50
OKFunction · 0.50
ToStringMethod · 0.45

Tested by

no test coverage detected