Skip to content

Commit

Permalink
Fix: left anti join filter empty rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
Light-City authored and pitrou committed Apr 15, 2024
1 parent a6cdcd0 commit 6bdcea8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cpp/src/arrow/acero/hash_join_node_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,25 @@ TEST(HashJoin, ResidualFilter) {
[3, 4, "alpha", 4, 16, "alpha"]])")});
}

TEST(HashJoin, FilterEmptyRows) {
BatchesWithSchema input_left;
input_left.batches = {ExecBatchFromJSON({int32(), utf8(), int32()}, R"([[2, "Jarry", 28]])")};
input_left.schema = schema({field("id", int32()), field("name", utf8()), field("age", int32())});

BatchesWithSchema input_right;
input_right.batches = {ExecBatchFromJSON(
{int32(), int32(), utf8()},
R"([[2, 10, "Jack"], [3, 12, "Mark"], [4, 15, "Tom"], [1, 10, "Jack"]])")};
input_right.schema = schema({field("id", int32()), field("stu_id", int32()), field("subject", utf8())});

const ResidualFilterCaseRunner runner{std::move(input_left), std::move(input_right)};

Expression filter = greater(field_ref("age"), literal(25));

runner.Run(JoinType::LEFT_ANTI, {"id"}, {"stu_id"}, std::move(filter),
{ExecBatchFromJSON({int32(), utf8(), int32()}, R"([[2, "Jarry", 28]])")});
}

TEST(HashJoin, TrivialResidualFilter) {
Expression always_true =
equal(call("add", {field_ref("l1"), field_ref("r1")}), literal(2)); // 1 + 1 == 2
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/acero/swiss_join.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,9 @@ Status JoinResidualFilter::FilterOneBatch(const ExecBatch& keypayload_batch,
bool output_key_ids, bool output_payload_ids,
arrow::util::TempVectorStack* temp_stack,
int* num_passing_rows) const {
if (num_batch_rows == 0) {
return Status::OK();
}
// Caller must do shortcuts for trivial filter.
ARROW_DCHECK(!filter_.IsNullLiteral() && filter_ != literal(true) &&
filter_ != literal(false));
Expand Down

0 comments on commit 6bdcea8

Please sign in to comment.