()
| 478 | } |
| 479 | |
| 480 | @Test |
| 481 | public void testForEachNoCombiner() throws Exception { |
| 482 | // test that combiner is NOT invoked when |
| 483 | // one of the elements in the foreach generate |
| 484 | // has a foreach in the plan without a distinct agg |
| 485 | String input[] = { |
| 486 | "pig1\t18\t2.1", |
| 487 | "pig2\t24\t3.3", |
| 488 | "pig5\t45\t2.4", |
| 489 | "pig1\t18\t2.1", |
| 490 | "pig1\t19\t2.1", |
| 491 | "pig2\t24\t4.5", |
| 492 | "pig1\t20\t3.1" }; |
| 493 | |
| 494 | Util.createInputFile(cluster, "forEachNoCombinerInput.txt", input); |
| 495 | PigServer pigServer = new PigServer(cluster.getExecType(), properties); |
| 496 | pigServer.registerQuery("a = load 'forEachNoCombinerInput.txt' as (name:chararray, age:int, gpa:double);"); |
| 497 | pigServer.registerQuery("b = group a by name;"); |
| 498 | pigServer.registerQuery("c = foreach b {" + |
| 499 | " z = a.age;" + |
| 500 | " generate group, z, SUM(a.age), SUM(a.gpa);};"); |
| 501 | |
| 502 | // make sure there is a combine plan in the explain output |
| 503 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 504 | PrintStream ps = new PrintStream(baos); |
| 505 | pigServer.explain("c", ps); |
| 506 | assertFalse(baos.toString().matches("(?si).*combine plan.*")); |
| 507 | |
| 508 | HashMap<String, Object[]> results = new HashMap<String, Object[]>(); |
| 509 | results.put("pig1", new Object[] { "pig1", "bag-place-holder", 75L, 9.4 }); |
| 510 | results.put("pig2", new Object[] { "pig2", "bag-place-holder", 48L, 7.8 }); |
| 511 | results.put("pig5", new Object[] { "pig5", "bag-place-holder", 45L, 2.4 }); |
| 512 | Iterator<Tuple> it = pigServer.openIterator("c"); |
| 513 | while (it.hasNext()) { |
| 514 | Tuple t = it.next(); |
| 515 | List<Object> fields = t.getAll(); |
| 516 | Object[] expected = results.get(fields.get(0)); |
| 517 | int i = 0; |
| 518 | for (Object field : fields) { |
| 519 | if (i == 1) { |
| 520 | // ignore the second field which is a bag |
| 521 | // for comparison here |
| 522 | continue; |
| 523 | } |
| 524 | assertEquals(expected[i++], field); |
| 525 | } |
| 526 | } |
| 527 | Util.deleteFile(cluster, "forEachNoCombinerInput.txt"); |
| 528 | pigServer.shutdown(); |
| 529 | } |
| 530 | |
| 531 | @Test |
| 532 | public void testJiraPig746() throws Exception { |
nothing calls this directly
no test coverage detected