allocateOutgoing();
}
if (incoming.getRecordCount() == 0) {
outer: while (true) {
IterOutcome out = outgoing.next(0, incoming);
switch (out) {
case OK_NEW_SCHEMA:
case OK:
if (incoming.getRecordCount() == 0) {
continue;
} else {
break outer;
}
case NONE:
out = IterOutcome.OK_NEW_SCHEMA;
case STOP:
default:
lastOutcome = out;
outcome = out;
done = true;
return AggOutcome.CLEANUP_AND_RETURN;
}
}
}
// pick up a remainder batch if we have one.
if(remainderBatch != null){
if (!outputToBatch( previousIndex )) return tooBigFailure();
remainderBatch.clear();
remainderBatch = null;
return setOkAndReturn();
}
// setup for new output and pick any remainder.
if (pendingOutput) {
allocateOutgoing();
pendingOutput = false;
if(EXTRA_DEBUG) logger.debug("Attempting to output remainder.");
if (!outputToBatch( previousIndex)) return tooBigFailure();
}
if(newSchema){
return AggOutcome.UPDATE_AGGREGATOR;
}
if(lastOutcome != null){
outcome = lastOutcome;
return AggOutcome.CLEANUP_AND_RETURN;
}
outside: while(true){
// loop through existing records, adding as necessary.
for (; underlyingIndex < incoming.getRecordCount(); incIndex()) {
if(EXTRA_DEBUG) logger.debug("Doing loop with values underlying {}, current {}", underlyingIndex, currentIndex);
if (previousIndex == -1) {
if (EXTRA_DEBUG) logger.debug("Adding the initial row's keys and values.");
addRecordInc(currentIndex);
}
else if (isSame( previousIndex, currentIndex )) {
if(EXTRA_DEBUG) logger.debug("Values were found the same, adding.");
addRecordInc(currentIndex);
} else {
if(EXTRA_DEBUG) logger.debug("Values were different, outputting previous batch.");
if (outputToBatch(previousIndex)) {
if(EXTRA_DEBUG) logger.debug("Output successful.");
addRecordInc(currentIndex);
} else {
if(EXTRA_DEBUG) logger.debug("Output failed.");
if(outputCount == 0) return tooBigFailure();
// mark the pending output but move forward for the next cycle.
pendingOutput = true;
previousIndex = currentIndex;
incIndex();
return setOkAndReturn();
}
}
previousIndex = currentIndex;
}
InternalBatch previous = null;
try{
while(true){
if (previous != null) {
previous.clear();
}
previous = new InternalBatch(incoming);
IterOutcome out = outgoing.next(0, incoming);
if(EXTRA_DEBUG) logger.debug("Received IterOutcome of {}", out);
switch(out){
case NONE:
done = true;
lastOutcome = out;