aggTypesArray[i] = aggGroup[i] + stage;
}
}
for(int k = 0; k < aggFinalTypes.length; k++) {
EvalFunc<?> aggInitial = evalFuncMap.get(aggInitialTypes[k]);
Tuple tup = inputMap.get(getInputType(aggInitialTypes[k]));
// To test this case, first <Agg>Initial is called for each input
// value. The output from <Agg>Initial for quarter of values from
// the inputs is put into one bag. Then 4 calls are made to Intermediate
// with each bag going to one call. This simulates the call in the map-combine
// boundary. The outputs from the first two calls to Intermediate above are
// put into a bag and the output from the next two calls put into another bag.
// These two bags are provided as inputs to two separate calls of <Agg>Intermediate.
// This simulates the call in the combine-reduce boundary.
// The outputs from the two calls to <Agg>Intermediate are put into a bag
// and sent as input to <Agg>Final
// The tuple we got above has a bag with input
// values. Lets call <Agg>Initial with each value:
DataBag bg = (DataBag) tup.get(0);
DataBag[] mapIntermediateInputBgs = new DataBag[4];
for (int i = 0; i < mapIntermediateInputBgs.length; i++) {
mapIntermediateInputBgs[i] = bagFactory.newDefaultBag();
}
Iterator<Tuple> it = bg.iterator();
for(int i = 0; i < 4; i++) {
for(int j = 0; j < bg.size()/4; j++) {
DataBag initialInputBg = bagFactory.newDefaultBag();
initialInputBg.add(it.next());
Tuple initialInputTuple = tupleFactory.newTuple(initialInputBg);
mapIntermediateInputBgs[i].add((Tuple)aggInitial.exec(initialInputTuple));
}
if(i == 3) {
// if the last quarter has more elements process them
while(it.hasNext()) {
DataBag initialInputBg = bagFactory.newDefaultBag();
initialInputBg.add(it.next());
Tuple initialInputTuple = tupleFactory.newTuple(initialInputBg);
mapIntermediateInputBgs[i].add((Tuple)aggInitial.exec(initialInputTuple));
}
}
}
EvalFunc<?> aggIntermediate = evalFuncMap.get(aggIntermediateTypes[k]);
DataBag[] reduceIntermediateInputBgs = new DataBag[2];
for (int i = 0; i < reduceIntermediateInputBgs.length; i++) {
reduceIntermediateInputBgs[i] = bagFactory.newDefaultBag();
}
// simulate call to combine after map
for(int i = 0; i < 4; i++) {
Tuple intermediateInputTuple = tupleFactory.newTuple(mapIntermediateInputBgs[i]);
if(i < 2) {
reduceIntermediateInputBgs[0].add((Tuple)aggIntermediate.exec(intermediateInputTuple));
} else {
reduceIntermediateInputBgs[1].add((Tuple)aggIntermediate.exec(intermediateInputTuple));
}
}
DataBag finalInputBag = bagFactory.newDefaultBag();
// simulate call to combine before reduce
for(int i = 0; i < 2; i++) {
Tuple intermediateInputTuple = tupleFactory.newTuple(reduceIntermediateInputBgs[i]);
finalInputBag.add((Tuple)aggIntermediate.exec(intermediateInputTuple));
}
// simulate call to final (in reduce)
Tuple finalInputTuple = tupleFactory.newTuple(finalInputBag);
EvalFunc<?> aggFinal = evalFuncMap.get(aggFinalTypes[k]);
String msg = "[Testing " + aggGroup[k] + " on input type: " + getInputType(aggFinalTypes[k]);
System.err.println(msg + " for multiple combiner case]");
Object output = aggFinal.exec(finalInputTuple);
msg += " ( (output) " + output + " == " + getExpected(aggFinalTypes[k]) + " (expected) )]";