public Tuple next() throws IOException {
if (first) {
loadRightToHashTable();
}
Tuple rightTuple;
boolean found = false;
while(!finished) {
if (shouldGetLeftTuple) { // initially, it is true.
// getting new outer
leftTuple = leftChild.next(); // it comes from a disk
if (leftTuple == null) { // if no more tuples in left tuples on disk, a join is completed.
// in this stage we can begin outputing tuples from the right operand (which were before in tupleSlots) null padded on the left side
Tuple unmatchedRightTuple = getNextUnmatchedRight();
if( unmatchedRightTuple == null) {
finished = true;
outTuple = null;
return null;
} else {
Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(leftNumCols);
frameTuple.set(nullPaddedTuple, unmatchedRightTuple);
projector.eval(evalContexts, frameTuple);
projector.terminate(evalContexts, outTuple);
return outTuple;
}
}
// getting corresponding right
getKeyLeftTuple(leftTuple, leftKeyTuple); // get a left key tuple
if (tupleSlots.containsKey(leftKeyTuple)) { // finds right tuples on in-memory hash table.
iterator = tupleSlots.get(leftKeyTuple).iterator();
shouldGetLeftTuple = false;
} else {
//this left tuple doesn't have a match on the right.But full outer join => we should keep it anyway
//output a tuple with the nulls padded rightTuple
Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(rightNumCols);
frameTuple.set(leftTuple, nullPaddedTuple);
projector.eval(evalContexts, frameTuple);
projector.terminate(evalContexts, outTuple);
// we simulate we found a match, which is exactly the null padded one
shouldGetLeftTuple = true;