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

Method runTest

test/org/apache/pig/test/TestPackage.java:61–133  ·  view source on GitHub ↗
(Object key, boolean inner[], byte keyType)

Source from the content-addressed store, hash-verified

59 private static final TupleFactory binfactory = BinSedesTupleFactory.getInstance();
60
61 private void runTest(Object key, boolean inner[], byte keyType) throws ExecException,
62 IOException {
63 Random r = new Random();
64 DataBag db1 = GenRandomData.genRandSmallTupDataBag(r, 10, 100);
65 DataBag db2 = GenRandomData.genRandSmallTupDataBag(r, 10, 100);
66 List<NullableTuple> db = new ArrayList<NullableTuple>(200);
67 Iterator<Tuple> db1Iter = db1.iterator();
68 if (!inner[0]) {
69 while (db1Iter.hasNext()) {
70 NullableTuple it = new NullableTuple(db1Iter.next());
71 it.setIndex((byte)0);
72 db.add(it);
73 }
74 }
75 Iterator<Tuple> db2Iter = db2.iterator();
76 while (db2Iter.hasNext()) {
77 NullableTuple it = new NullableTuple(db2Iter.next());
78 it.setIndex((byte)1);
79 db.add(it);
80 }
81 // ITIterator iti = new TestPackage.ITIterator(db.iterator());
82 POPackage pop = new POPackage(new OperatorKey("", r.nextLong()));
83 pop.setNumInps(2);
84 pop.getPkgr().setInner(inner);
85 PigNullableWritable k = HDataType.getWritableComparableTypes(key, keyType);
86 pop.attachInput(k, db.iterator());
87 if (keyType != DataType.BAG) {
88 // test serialization
89 NullablePartitionWritable wr;
90 if (keyType == DataType.TUPLE) {
91 BinSedesTuple tup = (BinSedesTuple) binfactory.newTupleNoCopy(((Tuple) k.getValueAsPigType()).getAll());
92 wr = new NullablePartitionWritable(new NullableTuple(tup));
93 } else {
94 wr = new NullablePartitionWritable(k);
95 }
96 ByteArrayOutputStream baos = new ByteArrayOutputStream();
97 DataOutputStream out = new DataOutputStream(baos);
98 wr.write(out);
99 byte[] arr = baos.toByteArray();
100 ByteArrayInputStream bais = new ByteArrayInputStream(arr);
101 DataInputStream in = new DataInputStream(bais);
102 NullablePartitionWritable re = new NullablePartitionWritable();
103 re.readFields(in);
104 assertEquals(re, wr);
105 }
106
107 // we are not doing any optimization to remove
108 // parts of the "value" which are present in the "key" in this
109 // unit test - so set up the "keyInfo" accordingly in
110 // the POPackage
111 Map<Integer, Pair<Boolean, Map<Integer, Integer>>> keyInfo =
112 new HashMap<Integer, Pair<Boolean, Map<Integer, Integer>>>();
113 Pair<Boolean, Map<Integer, Integer>> p =
114 new Pair<Boolean, Map<Integer, Integer>>(false, new HashMap<Integer, Integer>());
115 keyInfo.put(0, p);
116 keyInfo.put(1, p);
117 pop.getPkgr().setKeyInfo(keyInfo);
118 Tuple t = null;

Callers 1

pickTestMethod · 0.95

Calls 15

iteratorMethod · 0.95
setNumInpsMethod · 0.95
getPkgrMethod · 0.95
attachInputMethod · 0.95
getValueAsPigTypeMethod · 0.95
writeMethod · 0.95
readFieldsMethod · 0.95
getNextTupleMethod · 0.95
getMethod · 0.95
compareBagsMethod · 0.95

Tested by

no test coverage detected