while (true) { // loop until we find a tuple we're allowed to output (or we hit the end)
// find the smallest group among all inputs (this is the group we should make a tuple
// out of)
Datum smallestGroup = null;
for (int i = 0; i < inputs.length; i++) {
if (sortedInputs[i].size() > 0) {
Datum g = (sortedInputs[i].get(0))[0];
if (smallestGroup == null || g.compareTo(smallestGroup)<0)
smallestGroup = g;
}
}
if (smallestGroup == null)
return null; // we hit the end of the groups, so we're done
// find all tuples in each input pertaining to the group of interest, and combine the
// data into a single tuple
Tuple output;
ExampleTuple tOut = new ExampleTuple();
if (outputType == LogicalOperator.AMENDABLE) output = new AmendableTuple(1 + inputs.length, smallestGroup);
else output = new Tuple(1 + inputs.length);
// set first field to the group tuple
output.setField(0, smallestGroup);
tOut.copyFrom(output);
if (lineageTracer != null) lineageTracer.insert(tOut);
boolean done = true;
for (int i = 0; i < inputs.length; i++) {
DataBag b = BagFactory.getInstance().newDefaultBag();
while (sortedInputs[i].size() > 0) {
Datum g = sortedInputs[i].get(0)[0];
Tuple t = (Tuple) sortedInputs[i].get(0)[1];
if (g.compareTo(smallestGroup) < 0) {
sortedInputs[i].remove(0); // discard this tuple
} else if (g.equals(smallestGroup)) {
b.add(t);
//if (lineageTracer != null) lineageTracer.union(t, output); // update lineage
if (lineageTracer != null) {
if(((ExampleTuple)t).isSynthetic()) tOut.makeSynthetic();
lineageTracer.union(t, tOut); // update lineage