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

Method testValueTypesChanged

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

Source from the content-addressed store, hash-verified

2626 }
2627
2628 @Test
2629 public void testValueTypesChanged() throws IOException {
2630
2631 // Plan to test when result type is ByteArray and casting is requested
2632 // for example casting of values coming out of map lookup.
2633 POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
2634 PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
2635 DataBag bag = BagFactory.getInstance().newDefaultBag();
2636
2637 // Create a bag having tuples having values of different types.
2638 for(int i = 0; i < MAX; i++) {
2639 Tuple t = TupleFactory.getInstance().newTuple();
2640 if (i % 6 == 0)
2641 t.append(r.nextBoolean());
2642 if(i % 6 == 1)
2643 t.append(r.nextInt());
2644 if(i % 6 == 2)
2645 t.append(r.nextLong());
2646 if(i % 6 == 3)
2647 t.append(r.nextDouble());
2648 if(i % 6 == 4)
2649 t.append(r.nextFloat());
2650 if(i % 6 == 5)
2651 t.append(r.nextLong());
2652 bag.add(t);
2653 }
2654
2655 for(Iterator<Tuple> it = bag.iterator(); it.hasNext(); ) {
2656 Tuple t = it.next();
2657 planToTestBACasts.attachInput(t);
2658 Object toCast = t.get(0);
2659 Boolean b = DataType.toBoolean(toCast);
2660 Result res = opWithInputTypeAsBA.getNextBoolean();
2661 if (res.returnStatus == POStatus.STATUS_OK) {
2662 assertEquals(b, res.result);
2663 }
2664 Integer i = DataType.toInteger(toCast);
2665 res = opWithInputTypeAsBA.getNextInteger();
2666 if(res.returnStatus == POStatus.STATUS_OK) {
2667 assertEquals(i, res.result);
2668 }
2669 Long l = DataType.toLong(toCast);
2670 res = opWithInputTypeAsBA.getNextLong();
2671 if(res.returnStatus == POStatus.STATUS_OK) {
2672 assertEquals(l, res.result);
2673 }
2674
2675 Float f = DataType.toFloat(toCast);
2676 res = opWithInputTypeAsBA.getNextFloat();
2677 if(res.returnStatus == POStatus.STATUS_OK) {
2678 assertEquals(f, res.result);
2679 }
2680
2681 Double d = DataType.toDouble(toCast);
2682 res = opWithInputTypeAsBA.getNextDouble();
2683 if(res.returnStatus == POStatus.STATUS_OK) {
2684 assertEquals(d, res.result);
2685 }

Callers

nothing calls this directly

Calls 15

constructPlanMethod · 0.95
getInstanceMethod · 0.95
getInstanceMethod · 0.95
appendMethod · 0.95
addMethod · 0.95
iteratorMethod · 0.95
attachInputMethod · 0.95
getMethod · 0.95
toBooleanMethod · 0.95
getNextBooleanMethod · 0.95
toIntegerMethod · 0.95
getNextIntegerMethod · 0.95

Tested by

no test coverage detected