MCPcopy Create free account
hub / github.com/apache/pig / testAggSingleCombine

Method testAggSingleCombine

test/org/apache/pig/test/TestBuiltin.java:627–710  ·  view source on GitHub ↗

Test the case where the combiner is called once - so initial is called and then Intermediate and then final is called @throws Exception

()

Source from the content-addressed store, hash-verified

625 * @throws Exception
626 */
627 @Test
628 public void testAggSingleCombine() throws Exception {
629
630 for (String[] aggGroup : aggs) {
631 String[] aggFinalTypes = null; // will contains AVGFinal, DoubleAvgFinal etc
632 String[] aggInitialTypes = null; // will contains AVGInitial, DoubleAvgInitial etc
633 String[] aggIntermediateTypes = null; // will contains AVGIntermediate, DoubleAvgIntermediate etc
634 for (String stage: stages) {
635 String[] aggTypesArray = null;
636 if (stage.equals("Initial")) {
637 aggInitialTypes = new String[aggGroup.length];
638 aggTypesArray = aggInitialTypes;
639 } else if (stage.equals("Intermediate")) {
640 aggIntermediateTypes = new String[aggGroup.length];
641 aggTypesArray = aggIntermediateTypes;
642 } else {// final
643 aggFinalTypes = new String[aggGroup.length];
644 aggTypesArray = aggFinalTypes;
645 }
646
647 for (int i = 0; i < aggTypesArray.length; i++) {
648 aggTypesArray[i] = aggGroup[i] + stage;
649 }
650 }
651 for (int k = 0; k < aggFinalTypes.length; k++) {
652 EvalFunc<?> aggInitial = evalFuncMap.get(aggInitialTypes[k]);
653 Tuple tup = inputMap.get(getInputType(aggInitialTypes[k]));
654 // To test this case, first <Agg>Initial is called for each input
655 // value. The output from <Agg>Initial for the first half of inputs is
656 // put into one bag and the next half into another. Then these two
657 // bags are provided as inputs to two separate calls of <Agg>Intermediate.
658 // The outputs from the two calls to <Agg>Intermediate are put into a bag
659 // and sent as input to <Agg>Final
660
661 // The tuple we got above has a bag with input
662 // values. Lets call <Agg>Initial with each value:
663 DataBag bg = (DataBag) tup.get(0);
664 DataBag intermediateInputBg1 = bagFactory.newDefaultBag();
665 DataBag intermediateInputBg2 = bagFactory.newDefaultBag();
666 int i = 0;
667 for (Tuple tuple : bg) {
668 DataBag initialInputBg = bagFactory.newDefaultBag();
669 initialInputBg.add(tuple);
670 Tuple initialInputTuple = tupleFactory.newTuple(initialInputBg);
671 if (i < bg.size()/2) {
672 intermediateInputBg1.add((Tuple)aggInitial.exec(initialInputTuple));
673 } else {
674 intermediateInputBg2.add((Tuple)aggInitial.exec(initialInputTuple));
675 }
676 i++;
677 }
678
679 EvalFunc<?> avgIntermediate = evalFuncMap.get(aggIntermediateTypes[k]);
680 DataBag finalInputBg = bagFactory.newDefaultBag();
681 Tuple intermediateInputTuple = tupleFactory.newTuple(intermediateInputBg1);
682 finalInputBg.add((Tuple)avgIntermediate.exec(intermediateInputTuple));
683 intermediateInputTuple = tupleFactory.newTuple(intermediateInputBg2);
684 finalInputBg.add((Tuple)avgIntermediate.exec(intermediateInputTuple));

Callers

nothing calls this directly

Calls 11

getMethod · 0.95
getInputTypeMethod · 0.95
addMethod · 0.95
sizeMethod · 0.95
getExpectedMethod · 0.95
newTupleMethod · 0.65
equalsMethod · 0.45
newDefaultBagMethod · 0.45
execMethod · 0.45
assertEqualsMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected