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

Method testStringToOther

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

Source from the content-addressed store, hash-verified

1250 }
1251
1252 @Test
1253 public void testStringToOther() throws IOException {
1254 POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
1255 LoadFunc load = new TestLoader();
1256 op.setFuncSpec(new FuncSpec(load.getClass().getName()));
1257 POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
1258 PhysicalPlan plan = new PhysicalPlan();
1259 plan.add(prj);
1260 plan.add(op);
1261 plan.connect(prj, op);
1262
1263 prj.setResultType(DataType.CHARARRAY);
1264
1265 // Plan to test when result type is ByteArray and casting is requested
1266 // for example casting of values coming out of map lookup.
1267 POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
1268 PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
1269
1270 TupleFactory tf = TupleFactory.getInstance();
1271
1272 {
1273 Tuple t = tf.newTuple();
1274 t.append((new Boolean(r.nextBoolean())).toString());
1275 plan.attachInput(t);
1276 String str = (String) t.get(0);
1277 Boolean b = null;
1278 if (str.equalsIgnoreCase("true")) {
1279 b = Boolean.TRUE;
1280 } else if (str.equalsIgnoreCase("false")) {
1281 b = Boolean.FALSE;
1282 }
1283 Result res = op.getNextBoolean();
1284 if (res.returnStatus == POStatus.STATUS_OK) {
1285 // System.out.println(res.result + " : " + i);
1286 assertEquals(b, res.result);
1287 }
1288 planToTestBACasts.attachInput(t);
1289 res = opWithInputTypeAsBA.getNextBoolean();
1290 if (res.returnStatus == POStatus.STATUS_OK)
1291 assertEquals(b, res.result);
1292
1293 t = tf.newTuple();
1294 t.append("neither true nor false");
1295 plan.attachInput(t);
1296 res = op.getNextBoolean();
1297 if (res.returnStatus == POStatus.STATUS_OK) {
1298 // System.out.println(res.result + " : " + i);
1299 assertEquals(null, res.result);
1300 }
1301 planToTestBACasts.attachInput(t);
1302 res = opWithInputTypeAsBA.getNextBoolean();
1303 if (res.returnStatus == POStatus.STATUS_OK)
1304 assertEquals(null, res.result);
1305 }
1306
1307 {
1308 Tuple t = tf.newTuple();
1309 t.append((new Integer(r.nextInt())).toString());

Callers

nothing calls this directly

Calls 15

setFuncSpecMethod · 0.95
connectMethod · 0.95
constructPlanMethod · 0.95
getInstanceMethod · 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