Skip to content

Commit

Permalink
Literal false and null
Browse files Browse the repository at this point in the history
  • Loading branch information
zanmato1984 committed Jan 11, 2024
1 parent a687bb0 commit 8f9db83
Showing 1 changed file with 171 additions and 0 deletions.
171 changes: 171 additions & 0 deletions cpp/src/arrow/acero/hash_join_node_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,177 @@ TEST(HashJoin, FineGrainedResidualFilter) {
}
}
}

{
// Literal false and null.
for (Expression filter : {literal(false), literal(NullScalar())}) {
std::vector<FieldRef> left_keys{"l_key", "l_filter"},
right_keys{"r_key", "r_filter"};
{
// Inner join.
JoinType join_type = JoinType::INNER;
auto expected = ExecBatchFromJSON(
{utf8(), int32(), utf8(), utf8(), int32(), utf8()}, R"([])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}

{
// Left outer join.
JoinType join_type = JoinType::LEFT_OUTER;
auto expected =
ExecBatchFromJSON({utf8(), int32(), utf8(), utf8(), int32(), utf8()}, R"([
[null, null, "payload", null, null, null],
[null, 0, "payload", null, null, null],
[null, 42, "payload", null, null, null],
["left_only", null, "payload", null, null, null],
["left_only", 0, "payload", null, null, null],
["left_only", 42, "payload", null, null, null],
["both1", null, "payload", null, null, null],
["both1", 0, "payload", null, null, null],
["both1", 42, "payload", null, null, null],
["both2", null, "payload", null, null, null],
["both2", 0, "payload", null, null, null],
["both2", 42, "payload", null, null, null]])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}

{
// Right outer join.
JoinType join_type = JoinType::RIGHT_OUTER;
auto expected =
ExecBatchFromJSON({utf8(), int32(), utf8(), utf8(), int32(), utf8()}, R"([
[null, null, null, null, null, "payload"],
[null, null, null, null, 0, "payload"],
[null, null, null, null, 42, "payload"],
[null, null, null, "both1", null, "payload"],
[null, null, null, "both1", 0, "payload"],
[null, null, null, "both1", 42, "payload"],
[null, null, null, "both2", null, "payload"],
[null, null, null, "both2", 0, "payload"],
[null, null, null, "both2", 42, "payload"],
[null, null, null, "right_only", null, "payload"],
[null, null, null, "right_only", 0, "payload"],
[null, null, null, "right_only", 42, "payload"]])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}

{
// Full outer join.
JoinType join_type = JoinType::FULL_OUTER;
auto expected =
ExecBatchFromJSON({utf8(), int32(), utf8(), utf8(), int32(), utf8()}, R"([
[null, null, "payload", null, null, null],
[null, 0, "payload", null, null, null],
[null, 42, "payload", null, null, null],
["left_only", null, "payload", null, null, null],
["left_only", 0, "payload", null, null, null],
["left_only", 42, "payload", null, null, null],
["both1", null, "payload", null, null, null],
["both1", 0, "payload", null, null, null],
["both1", 42, "payload", null, null, null],
["both2", null, "payload", null, null, null],
["both2", 0, "payload", null, null, null],
["both2", 42, "payload", null, null, null],
[null, null, null, null, null, "payload"],
[null, null, null, null, 0, "payload"],
[null, null, null, null, 42, "payload"],
[null, null, null, "both1", null, "payload"],
[null, null, null, "both1", 0, "payload"],
[null, null, null, "both1", 42, "payload"],
[null, null, null, "both2", null, "payload"],
[null, null, null, "both2", 0, "payload"],
[null, null, null, "both2", 42, "payload"],
[null, null, null, "right_only", null, "payload"],
[null, null, null, "right_only", 0, "payload"],
[null, null, null, "right_only", 42, "payload"]])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}

{
// Left semi join.
JoinType join_type = JoinType::LEFT_SEMI;
auto expected = ExecBatchFromJSON({utf8(), int32(), utf8()}, R"([])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}

{
// Left anti join.
JoinType join_type = JoinType::LEFT_ANTI;
auto expected = ExecBatchFromJSON({utf8(), int32(), utf8()}, R"([
[null, null, "payload"],
[null, 0, "payload"],
[null, 42, "payload"],
["left_only", null, "payload"],
["left_only", 0, "payload"],
["left_only", 42, "payload"],
["both1", null, "payload"],
["both1", 0, "payload"],
["both1", 42, "payload"],
["both2", null, "payload"],
["both2", 0, "payload"],
["both2", 42, "payload"]])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}

{
// Right semi join.
JoinType join_type = JoinType::RIGHT_SEMI;
auto expected = ExecBatchFromJSON({utf8(), int32(), utf8()}, R"([])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}

{
// Right anti join.
JoinType join_type = JoinType::RIGHT_ANTI;
auto expected = ExecBatchFromJSON({utf8(), int32(), utf8()}, R"([
[null, null, "payload"],
[null, 0, "payload"],
[null, 42, "payload"],
["both1", null, "payload"],
["both1", 0, "payload"],
["both1", 42, "payload"],
["both2", null, "payload"],
["both2", 0, "payload"],
["both2", 42, "payload"],
["right_only", null, "payload"],
["right_only", 0, "payload"],
["right_only", 42, "payload"]])");
for (const auto& projector : projectors) {
runner.Run(join_type, left_keys, right_keys, projector.LeftOutput(join_type),
projector.RightOutput(join_type), filter,
{projector.Project(join_type, expected)});
}
}
}
}
}

HashJoinNodeOptions GenerateHashJoinNodeOptions(Random64Bit& rng, int num_left_cols,
Expand Down

0 comments on commit 8f9db83

Please sign in to comment.