zanmato1984 commented on code in PR #39487:
URL: https://github.com/apache/arrow/pull/39487#discussion_r1462862280
##########
cpp/src/arrow/acero/hash_join_node_test.cc:
##########
@@ -1893,58 +1893,146 @@ TEST(HashJoin, CheckHashJoinNodeOptionsValidation) {
}
}
-TEST(HashJoin, ResidualFilter) {
- for (bool parallel : {false, true}) {
- SCOPED_TRACE(parallel ? "parallel/merged" : "serial");
-
- BatchesWithSchema input_left;
- input_left.batches = {ExecBatchFromJSON({int32(), int32(), utf8()}, R"([
- [1, 6, "alpha"],
- [2, 5, "beta"],
- [3, 4, "alpha"]
- ])")};
- input_left.schema =
- schema({field("l1", int32()), field("l2", int32()), field("l_str",
utf8())});
-
- BatchesWithSchema input_right;
- input_right.batches = {ExecBatchFromJSON({int32(), int32(), utf8()}, R"([
- [5, 11, "alpha"],
- [2, 12, "beta"],
- [4, 16, "alpha"]
- ])")};
- input_right.schema =
- schema({field("r1", int32()), field("r2", int32()), field("r_str",
utf8())});
+class ResidualFilterCaseRunner {
+ public:
+ ResidualFilterCaseRunner(BatchesWithSchema left_input, BatchesWithSchema
right_input)
+ : left_input_(std::move(left_input)),
right_input_(std::move(right_input)) {}
+
+ void Run(JoinType join_type, const std::vector<FieldRef>& left_keys,
+ const std::vector<FieldRef>& right_keys, Expression filter,
+ const std::vector<ExecBatch>& expected) const {
+ RunInternal(HashJoinNodeOptions{join_type, std::move(left_keys),
+ std::move(right_keys), std::move(filter)},
+ expected);
+ }
+
+ void Run(JoinType join_type, std::vector<FieldRef> left_keys,
+ const std::vector<FieldRef> right_keys, std::vector<FieldRef>
left_output,
+ const std::vector<FieldRef> right_output, Expression filter,
+ const std::vector<ExecBatch>& expected) const {
+ RunInternal(HashJoinNodeOptions{join_type, std::move(left_keys),
+ std::move(right_keys),
std::move(left_output),
+ std::move(right_output),
std::move(filter)},
+ expected);
+ }
+
+ private:
+ void RunInternal(const HashJoinNodeOptions& options,
+ const std::vector<ExecBatch>& expected) const {
+ auto join_type_str = JoinTypeString(options.join_type);
+ auto join_cond_str =
+ JoinConditionString(options.left_keys, options.right_keys,
options.filter);
+ auto output_str = OutputString(options.left_output, options.right_output);
+ for (bool parallel : {false, true}) {
+ auto parallel_str = parallel ? "parallel" : "serial";
+ SCOPED_TRACE(join_type_str + " " + join_cond_str + " " + output_str + "
" +
+ parallel_str);
- Declaration left{
- "source",
- SourceNodeOptions{input_left.schema, input_left.gen(parallel,
/*slow=*/false)}};
- Declaration right{
- "source",
- SourceNodeOptions{input_right.schema, input_right.gen(parallel,
/*slow=*/false)}};
+ Declaration left{"source",
+ SourceNodeOptions{left_input_.schema,
+ left_input_.gen(parallel,
/*slow=*/false)}};
+ Declaration right{"source",
+ SourceNodeOptions{right_input_.schema,
+ right_input_.gen(parallel,
/*slow=*/false)}};
- Expression mul = call("multiply", {field_ref("l1"), field_ref("l2")});
- Expression combination = call("add", {mul, field_ref("r1")});
- Expression residual_filter = less_equal(combination, field_ref("r2"));
+ Declaration join{"hashjoin", {std::move(left), std::move(right)},
options};
- HashJoinNodeOptions join_opts{
- JoinType::FULL_OUTER,
- /*left_keys=*/{"l_str"},
- /*right_keys=*/{"r_str"}, std::move(residual_filter), "l_", "r_"};
+ ASSERT_OK_AND_ASSIGN(auto result,
+ DeclarationToExecBatches(std::move(join),
parallel));
+ AssertExecBatchesEqualIgnoringOrder(result.schema, expected,
result.batches);
+ }
+ }
- Declaration join{"hashjoin", {std::move(left), std::move(right)},
join_opts};
+ private:
+ BatchesWithSchema left_input_;
+ BatchesWithSchema right_input_;
- ASSERT_OK_AND_ASSIGN(auto result,
- DeclarationToExecBatches(std::move(join), parallel));
+ private:
+ static std::string JoinTypeString(JoinType t) {
+ switch (t) {
+ case JoinType::LEFT_SEMI:
+ return "LEFT_SEMI";
+ case JoinType::RIGHT_SEMI:
+ return "RIGHT_SEMI";
+ case JoinType::LEFT_ANTI:
+ return "LEFT_ANTI";
+ case JoinType::RIGHT_ANTI:
+ return "RIGHT_ANTI";
+ case JoinType::INNER:
+ return "INNER";
+ case JoinType::LEFT_OUTER:
+ return "LEFT_OUTER";
+ case JoinType::RIGHT_OUTER:
+ return "RIGHT_OUTER";
+ case JoinType::FULL_OUTER:
+ return "FULL_OUTER";
+ }
+ ARROW_DCHECK(false);
+ return "";
+ }
+
+ static std::string JoinConditionString(const std::vector<FieldRef>&
left_keys,
+ const std::vector<FieldRef>&
right_keys,
+ const Expression& filter) {
+ ARROW_DCHECK(left_keys.size() > 0);
+ ARROW_DCHECK(left_keys.size() == right_keys.size());
+ std::stringstream ss;
+ ss << "on (";
+ for (size_t i = 0; i < left_keys.size(); ++i) {
+ ss << left_keys[i].ToString() << " = " << right_keys[i].ToString() << "
and ";
+ }
+ ss << filter.ToString();
+ ss << ")";
+ return ss.str();
+ }
+
+ static std::string OutputString(const std::vector<FieldRef>& left_output,
Review Comment:
I'm thinking maybe we can make obtaining join type string and output string
generic in the scope of this test file. So both `HashJoin.Random` and this one
can leverage it. How does that sound?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]