endInPopulationStage = false;
boolean endLeft = false;
boolean endRight = false;
previous = new VTuple(leftTuple);
do {
leftTupleSlots.add(new VTuple(leftTuple));
leftTuple = leftChild.next();
if(leftTuple == null) {
endLeft = true;
}
} while ((endLeft != true) && (tupleComparator[0].compare(previous, leftTuple) == 0));
posLeftTupleSlots = 0;
previous = new VTuple(rightTuple);
do {
rightTupleSlots.add(new VTuple(rightTuple));
rightTuple = rightChild.next();
if(rightTuple == null) {
endRight = true;
}
} while ((endRight != true) && (tupleComparator[1].compare(previous, rightTuple) == 0) );
posRightTupleSlots = 0;
if ((endLeft == true) || (endRight == true)) {
end = true;
endInPopulationStage = true;
}
} // if end false
} // if newRound
////////////////////////////////////////////////////////////////////////
// RESULTS STAGE
////////////////////////////////////////////////////////////////////////
// now output result matching tuples from the slots
// if either we haven't reached end on neither side, or we did reach end
// on one(or both) sides but that happened in the slots population step
// (i.e. refers to next round)
if(!end || (end && endInPopulationStage)){
if(posLeftTupleSlots == 0){
leftNext = new VTuple (leftTupleSlots.get(posLeftTupleSlots));
posLeftTupleSlots = posLeftTupleSlots + 1;
}
if(posRightTupleSlots <= (rightTupleSlots.size() -1)) {
Tuple aTuple = new VTuple(rightTupleSlots.get(posRightTupleSlots));
posRightTupleSlots = posRightTupleSlots + 1;
frameTuple.set(leftNext, aTuple);
joinQual.eval(qualCtx, inSchema, frameTuple);
projector.eval(evalContexts, frameTuple);
projector.terminate(evalContexts, outTuple);
return outTuple;
} else {
// right (inner) slots reached end and should be rewind if there are still tuples in the outer slots
if(posLeftTupleSlots <= (leftTupleSlots.size()-1)) {
//rewind the right slots position
posRightTupleSlots = 0;
Tuple aTuple = new VTuple(rightTupleSlots.get(posRightTupleSlots));
posRightTupleSlots = posRightTupleSlots + 1;
leftNext = new VTuple (leftTupleSlots.get(posLeftTupleSlots));
posLeftTupleSlots = posLeftTupleSlots + 1;
frameTuple.set(leftNext, aTuple);
joinQual.eval(qualCtx, inSchema, frameTuple);
projector.eval(evalContexts, frameTuple);