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

Method testAVGIntermediate

test/org/apache/pig/test/TestBuiltin.java:980–1049  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

978 }
979
980 @Test
981 public void testAVGIntermediate() throws Exception {
982 String[] avgTypes = {"AVGIntermediate", "DoubleAvgIntermediate", "LongAvgIntermediate", "IntAvgIntermediate", "FloatAvgIntermediate",
983 "BigDecimalAvgIntermediate", "BigIntegerAvgIntermediate"};
984 for (int k = 0; k < avgTypes.length; k++) {
985 EvalFunc<?> avg = evalFuncMap.get(avgTypes[k]);
986 String inputType = getInputType(avgTypes[k]);
987 Tuple tup = inputMap.get(inputType);
988 // The tuple we got above has a bag with input
989 // values. Input to the Intermediate.exec() however comes
990 // from the map which would put each value and a count of
991 // 1 in a tuple and send it down. So lets create a bag with
992 // tuples that have two fields - the value and a count 1.
993 DataBag bag = (DataBag) tup.get(0);
994 DataBag bg = bagFactory.newDefaultBag();
995 for (Tuple t: bag) {
996 Tuple newTuple = tupleFactory.newTuple(2);
997 newTuple.set(0, t.get(0));
998 if (inputType == "BigDecimal") {
999 newTuple.set(1, BigDecimal.ONE);
1000 } else if (inputType == "BigInteger") {
1001 newTuple.set(1, BigInteger.ONE);
1002 } else {
1003 newTuple.set(1, new Long(1));
1004 }
1005 bg.add(newTuple);
1006 }
1007 Tuple intermediateInput = tupleFactory.newTuple();
1008 intermediateInput.append(bg);
1009
1010 Object output = avg.exec(intermediateInput);
1011
1012 if (inputType == "Long" || inputType == "Integer" || inputType == "IntegerAsLong") {
1013 Long l = (Long)((Tuple)output).get(0);
1014 String msg = "[Testing " + avgTypes[k] + " on input type: " + getInputType(avgTypes[k]) + " ( (output) " +
1015 l + " == " + getExpected(avgTypes[k]) + " (expected) )]";
1016 assertEquals(msg, getExpected(avgTypes[k]), l);
1017 } else if (inputType == "BigDecimal") {
1018 BigDecimal f1 = (BigDecimal)((Tuple)output).get(0);
1019 String msg = "[Testing " + avgTypes[k] + " on input type: " + getInputType(avgTypes[k]) + " ( (output) " +
1020 f1 + " == " + getExpected(avgTypes[k]) + " (expected) )]";
1021 assertEquals(msg, ((BigDecimal)getExpected(avgTypes[k])).toPlainString(), f1.toPlainString());
1022 } else if (inputType == "BigInteger") {
1023 BigInteger f1 = (BigInteger)((Tuple)output).get(0);
1024 String msg = "[Testing " + avgTypes[k] + " on input type: " + getInputType(avgTypes[k]) + " ( (output) " +
1025 f1 + " == " + getExpected(avgTypes[k]) + " (expected) )]";
1026 assertEquals(msg, ((BigInteger)getExpected(avgTypes[k])).toString(), f1.toString());
1027 } else {
1028 Double f1 = (Double)((Tuple)output).get(0);
1029 String msg = "[Testing " + avgTypes[k] + " on input type: " + getInputType(avgTypes[k]) + " ( (output) " +
1030 f1 + " == " + getExpected(avgTypes[k]) + " (expected) )]";
1031 assertEquals(msg, (Double)getExpected(avgTypes[k]), f1, 0.00001);
1032 }
1033 if (inputType == "BigDecimal") {
1034 BigDecimal f2 = (BigDecimal)((Tuple)output).get(1);
1035 assertEquals("[Testing " + avgTypes[k] + " on input type: "+
1036 inputType+"]Expected count to be 4", "4", f2.toPlainString());
1037

Callers

nothing calls this directly

Calls 11

getMethod · 0.95
getInputTypeMethod · 0.95
setMethod · 0.95
addMethod · 0.95
appendMethod · 0.95
getExpectedMethod · 0.95
newTupleMethod · 0.65
newDefaultBagMethod · 0.45
execMethod · 0.45
assertEqualsMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected