Skip to content

Commit ded5eeb

Browse files
committed
Address comments
1 parent b1dbce8 commit ded5eeb

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/enclave/Enclave/ExpressionEvaluation.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,8 @@ class FlatbuffersJoinExprEvaluator {
18331833
return is_primary(row1) ? row1 : row2;
18341834
}
18351835

1836-
/** Return true if the two rows are from the same join group */
1836+
/** Return true if the two rows are from the same join group
1837+
* Since the function calls `is_primary`, the rows must have been tagged in Scala */
18371838
bool is_same_group(const tuix::Row *row1, const tuix::Row *row2) {
18381839
builder.Clear();
18391840
bool row1_equals_row2;
@@ -1880,6 +1881,10 @@ class FlatbuffersJoinExprEvaluator {
18801881
const tuix::Field *condition_result = condition_eval->eval(concat_ptr);
18811882
return static_cast<const tuix::BooleanField *>(condition_result->value())->value();
18821883
}
1884+
1885+
// The `condition_eval` can only be empty when it's an equi-join.
1886+
// Since `condition_eval` is an extra predicate used to filter out *matched* rows in an equi-join, an empty
1887+
// condition means the matched row should not be filtered out; hence the default return value of true
18831888
return true;
18841889
}
18851890

src/enclave/Enclave/NonObliviousSortMergeJoin.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ void write_output_rows(RowWriter &group, RowWriter &w) {
3535

3636
/**
3737
* Sort merge equi join algorithm
38-
* Input: the rows are unioned from both the left (primary) table and the right (foreign) table
38+
* Input: the rows are unioned from both the primary (or left) table and the non-primary (or right) table
3939
*
4040
* Outer loop: iterate over all input rows
4141
*
4242
* If it's a row from the left table
4343
* - Add it to the current group
4444
* - Otherwise start a new group
45-
* - If it's a left semi/anti join, output the left_matched_rows/left_unmatched_rows
45+
* - If it's a left semi/anti join, output the primary_matched_rows/primary_unmatched_rows
4646
*
4747
* If it's a row from the right table
48-
* - Inner join: iterate over current primary group, output the joined row only if the condition is satisfied
49-
* - Left semi/anti join: iterate over `left_unmatched_rows`, add a matched row to `left_matched_rows`
50-
* and remove from `left_unmatched_rows`
48+
* - Inner join: iterate over current left group, output the joined row only if the condition is satisfied
49+
* - Left semi/anti join: iterate over `primary_unmatched_rows`, add a matched row to `primary_matched_rows`
50+
* and remove from `primary_unmatched_rows`
5151
*
5252
* After loop: output the last group left semi/anti join
5353
*/
@@ -64,7 +64,7 @@ void non_oblivious_sort_merge_join(
6464

6565
RowWriter primary_group;
6666
FlatbuffersTemporaryRow last_primary_of_group;
67-
RowWriter left_matched_rows, left_unmatched_rows; // This is only used for left semi/anti join
67+
RowWriter primary_matched_rows, primary_unmatched_rows; // This is only used for left semi/anti join
6868

6969
while (r.has_next()) {
7070
const tuix::Row *current = r.next();
@@ -74,27 +74,27 @@ void non_oblivious_sort_merge_join(
7474
&& join_expr_eval.is_same_group(last_primary_of_group.get(), current)) {
7575

7676
// Add this primary row to the current group
77-
// If this is a left semi/anti join, also add the rows to the left group
77+
// If this is a left semi/anti join, also add the rows to primary_unmatched_rows
7878
primary_group.append(current);
7979
if (join_type == tuix::JoinType_LeftSemi || join_type == tuix::JoinType_LeftAnti) {
80-
left_unmatched_rows.append(current);
80+
primary_unmatched_rows.append(current);
8181
}
8282
last_primary_of_group.set(current);
8383

8484
} else {
8585
// If a new primary group is encountered
8686
if (join_type == tuix::JoinType_LeftSemi) {
87-
write_output_rows(left_matched_rows, w);
87+
write_output_rows(primary_matched_rows, w);
8888
} else if (join_type == tuix::JoinType_LeftAnti) {
89-
write_output_rows(left_unmatched_rows, w);
89+
write_output_rows(primary_unmatched_rows, w);
9090
}
9191

9292
primary_group.clear();
93-
left_unmatched_rows.clear();
94-
left_matched_rows.clear();
93+
primary_unmatched_rows.clear();
94+
primary_matched_rows.clear();
9595

9696
primary_group.append(current);
97-
left_unmatched_rows.append(current);
97+
primary_unmatched_rows.append(current);
9898
last_primary_of_group.set(current);
9999
}
100100
} else {
@@ -112,36 +112,36 @@ void non_oblivious_sort_merge_join(
112112
}
113113
}
114114
} else if (join_type == tuix::JoinType_LeftSemi || join_type == tuix::JoinType_LeftAnti) {
115-
auto left_unmatched_rows_buffer = left_unmatched_rows.output_buffer();
116-
RowReader left_unmatched_rows_reader(left_unmatched_rows_buffer.view());
117-
RowWriter new_left_unmatched_rows;
115+
auto primary_unmatched_rows_buffer = primary_unmatched_rows.output_buffer();
116+
RowReader primary_unmatched_rows_reader(primary_unmatched_rows_buffer.view());
117+
RowWriter new_primary_unmatched_rows;
118118

119-
while (left_unmatched_rows_reader.has_next()) {
120-
const tuix::Row *primary = left_unmatched_rows_reader.next();
119+
while (primary_unmatched_rows_reader.has_next()) {
120+
const tuix::Row *primary = primary_unmatched_rows_reader.next();
121121
test_rows_same_group(join_expr_eval, primary, current);
122122
if (join_expr_eval.eval_condition(primary, current)) {
123-
left_matched_rows.append(primary);
123+
primary_matched_rows.append(primary);
124124
} else {
125-
new_left_unmatched_rows.append(primary);
125+
new_primary_unmatched_rows.append(primary);
126126
}
127127
}
128128

129-
// Reset left_unmatched_rows
130-
left_unmatched_rows.clear();
131-
auto new_left_unmatched_rows_buffer = new_left_unmatched_rows.output_buffer();
132-
RowReader new_left_unmatched_rows_reader(new_left_unmatched_rows_buffer.view());
133-
while (new_left_unmatched_rows_reader.has_next()) {
134-
left_unmatched_rows.append(new_left_unmatched_rows_reader.next());
129+
// Reset primary_unmatched_rows
130+
primary_unmatched_rows.clear();
131+
auto new_primary_unmatched_rows_buffer = new_primary_unmatched_rows.output_buffer();
132+
RowReader new_primary_unmatched_rows_reader(new_primary_unmatched_rows_buffer.view());
133+
while (new_primary_unmatched_rows_reader.has_next()) {
134+
primary_unmatched_rows.append(new_primary_unmatched_rows_reader.next());
135135
}
136136
}
137137
}
138138
}
139139
}
140140

141141
if (join_type == tuix::JoinType_LeftSemi) {
142-
write_output_rows(left_matched_rows, w);
142+
write_output_rows(primary_matched_rows, w);
143143
} else if (join_type == tuix::JoinType_LeftAnti) {
144-
write_output_rows(left_unmatched_rows, w);
144+
write_output_rows(primary_unmatched_rows, w);
145145
}
146146

147147
w.output_buffer(output_rows, output_rows_length);

0 commit comments

Comments
 (0)