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

Method testByteArrayToOther

test/org/apache/pig/test/TestPOCast.java:1631–1833  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1629 }
1630
1631 @Test
1632 public void testByteArrayToOther() throws IOException {
1633 POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
1634 LoadFunc load = new TestLoader();
1635 op.setFuncSpec(new FuncSpec(load.getClass().getName()));
1636 POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
1637 PhysicalPlan plan = new PhysicalPlan();
1638 plan.add(prj);
1639 plan.add(op);
1640 plan.connect(prj, op);
1641
1642 prj.setResultType(DataType.BYTEARRAY);
1643
1644 TupleFactory tf = TupleFactory.getInstance();
1645
1646 // Plan to test when result type is ByteArray and casting is requested
1647 // for example casting of values coming out of map lookup.
1648 POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
1649 PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
1650 {
1651 Tuple t = tf.newTuple();
1652 t.append(new DataByteArray((new Boolean(r.nextBoolean())).toString()
1653 .getBytes()));
1654 plan.attachInput(t);
1655 String str = ((DataByteArray) t.get(0)).toString();
1656 Boolean b = null;
1657 if (str.equalsIgnoreCase("true")) {
1658 b = Boolean.TRUE;
1659 } else if (str.equalsIgnoreCase("false")) {
1660 b = Boolean.FALSE;
1661 }
1662 Result res = op.getNextBoolean();
1663 if (res.returnStatus == POStatus.STATUS_OK) {
1664 // System.out.println(res.result + " : " + i);
1665 assertEquals(b, res.result);
1666 }
1667
1668 planToTestBACasts.attachInput(t);
1669 res = opWithInputTypeAsBA.getNextBoolean();
1670 if (res.returnStatus == POStatus.STATUS_OK)
1671 assertEquals(b, res.result);
1672
1673 }
1674
1675 {
1676 Tuple t = tf.newTuple();
1677 t.append(new DataByteArray((new Integer(r.nextInt())).toString().getBytes()));
1678 plan.attachInput(t);
1679 Integer i = Integer.valueOf(((DataByteArray) t.get(0)).toString());
1680 Result res = op.getNextInteger();
1681 if(res.returnStatus == POStatus.STATUS_OK) {
1682 //System.out.println(res.result + " : " + i);
1683 assertEquals(i, res.result);
1684 }
1685
1686 planToTestBACasts.attachInput(t);
1687 res = opWithInputTypeAsBA.getNextInteger();
1688 if(res.returnStatus == POStatus.STATUS_OK)

Callers

nothing calls this directly

Calls 15

setFuncSpecMethod · 0.95
connectMethod · 0.95
getInstanceMethod · 0.95
constructPlanMethod · 0.95
newTupleMethod · 0.95
appendMethod · 0.95
attachInputMethod · 0.95
getMethod · 0.95
getNextBooleanMethod · 0.95
getNextIntegerMethod · 0.95
getNextFloatMethod · 0.95
getNextLongMethod · 0.95

Tested by

no test coverage detected