Skip to content

Commit a1f9c0d

Browse files
committed
fix: only reject RIGHT and FULL joins, allow LEFT joins
The distributed shuffle join can correctly handle LEFT joins in the current implementation because each node executes the query locally and LEFT join only requires preserving unmatched left-table rows (which are already local to each node). RIGHT and FULL joins require tracking unmatched rows across partitions which is not yet implemented. Update error message to say "INNER and LEFT" instead of just "INNER".
1 parent 30895d6 commit a1f9c0d

2 files changed

Lines changed: 11 additions & 22 deletions

File tree

src/distributed/distributed_executor.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,14 @@ QueryResult DistributedExecutor::execute(const parser::Statement& stmt,
188188
const std::string left_table = select_stmt->from()->to_string();
189189
const std::string right_table = join.table->to_string();
190190

191-
// Check join type - shuffle join only supports INNER joins
192-
if (join.type != parser::SelectStatement::JoinType::Inner) {
191+
// Check join type - shuffle join only supports INNER and LEFT joins
192+
// RIGHT and FULL joins require tracking unmatched rows across partitions
193+
if (join.type == parser::SelectStatement::JoinType::Right ||
194+
join.type == parser::SelectStatement::JoinType::Full) {
193195
QueryResult res;
194-
std::string join_type_name;
195-
switch (join.type) {
196-
case parser::SelectStatement::JoinType::Left:
197-
join_type_name = "LEFT";
198-
break;
199-
case parser::SelectStatement::JoinType::Right:
200-
join_type_name = "RIGHT";
201-
break;
202-
case parser::SelectStatement::JoinType::Full:
203-
join_type_name = "FULL";
204-
break;
205-
default:
206-
join_type_name = "OUTER";
207-
break;
208-
}
209-
res.set_error("Distributed Shuffle Join only supports INNER joins. " +
196+
std::string join_type_name =
197+
(join.type == parser::SelectStatement::JoinType::Right) ? "RIGHT" : "FULL";
198+
res.set_error("Distributed Shuffle Join only supports INNER and LEFT joins. " +
210199
join_type_name +
211200
" joins are not yet supported in distributed mode.");
212201
return res;

tests/distributed_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ TEST(DistributedExecutorTests, RightJoinRejection) {
462462
auto res =
463463
exec.execute(*stmt, "SELECT * FROM table1 RIGHT JOIN table2 ON table1.id = table2.id");
464464

465-
// Should fail because distributed shuffle join only supports INNER joins
465+
// Should fail because distributed shuffle join only supports INNER and LEFT joins
466466
EXPECT_FALSE(res.success());
467-
EXPECT_THAT(res.error(), testing::HasSubstr("only supports INNER joins"));
467+
EXPECT_THAT(res.error(), testing::HasSubstr("only supports INNER and LEFT joins"));
468468
EXPECT_THAT(res.error(), testing::HasSubstr("RIGHT"));
469469
}
470470

@@ -483,9 +483,9 @@ TEST(DistributedExecutorTests, FullJoinRejection) {
483483
auto res =
484484
exec.execute(*stmt, "SELECT * FROM table1 FULL JOIN table2 ON table1.id = table2.id");
485485

486-
// Should fail because distributed shuffle join only supports INNER joins
486+
// Should fail because distributed shuffle join only supports INNER and LEFT joins
487487
EXPECT_FALSE(res.success());
488-
EXPECT_THAT(res.error(), testing::HasSubstr("only supports INNER joins"));
488+
EXPECT_THAT(res.error(), testing::HasSubstr("only supports INNER and LEFT joins"));
489489
EXPECT_THAT(res.error(), testing::HasSubstr("FULL"));
490490
}
491491

0 commit comments

Comments
 (0)