()
| 617 | } |
| 618 | |
| 619 | @Test |
| 620 | public void testInputOutputSpecs() throws Exception { |
| 621 | File input = Util.createInputFile("tmp", "", |
| 622 | new String[] {"A,1", "B,2", "C,3", |
| 623 | "D,2", "A,5", "B,5", |
| 624 | "C,8", "A,8", "D,8", |
| 625 | "A,9"}); |
| 626 | |
| 627 | // Perl script |
| 628 | String[] script = |
| 629 | new String[] { |
| 630 | "#!/usr/bin/perl", |
| 631 | "open(INFILE, $ARGV[0]) or die \"Can't open \".$ARGV[0].\"!: $!\";", |
| 632 | "open(OUTFILE, \">\", $ARGV[1]) or die \"Can't open \".$ARGV[1].\"!: $!\";", |
| 633 | "open(OUTFILE2, \">\", $ARGV[2]) or die \"Can't open \".$ARGV[2].\"!: $!\";", |
| 634 | "while (<INFILE>) {", |
| 635 | " chomp $_;", |
| 636 | " print OUTFILE \"$_\n\";", |
| 637 | " print STDERR \"STDERR: $_\n\";", |
| 638 | " print OUTFILE2 \"$_\n\";", |
| 639 | "}", |
| 640 | }; |
| 641 | File command = Util.createInputFile("script", "pl", script); |
| 642 | |
| 643 | // Expected results |
| 644 | String[] expectedFirstFields = |
| 645 | new String[] {"A", "B", "C", "A", "D", "A"}; |
| 646 | Integer[] expectedSecondFields = new Integer[] {5, 5, 8, 8, 8, 9}; |
| 647 | Tuple[] expectedResults = |
| 648 | setupExpectedResults(Util.toDataByteArrays(expectedFirstFields), |
| 649 | Util.toDataByteArrays(expectedSecondFields)); |
| 650 | // Pig query to run |
| 651 | pigServer.registerQuery( |
| 652 | "define CMD `perl " + command.getName() + " foo bar foobar` " + |
| 653 | "ship ('" + Util.encodeEscape(command.toString()) + "') " + |
| 654 | "input('foo' using " + PigStreaming.class.getName() + "(',')) " + |
| 655 | "output('bar', " + |
| 656 | "'foobar' using " + PigStreaming.class.getName() + "(',')) " + |
| 657 | "stderr();"); |
| 658 | pigServer.registerQuery("IP = load '" |
| 659 | + Util.generateURI(input.toString(), |
| 660 | pigServer.getPigContext()) + "' using " |
| 661 | + PigStorage.class.getName() + "(',');"); |
| 662 | pigServer.registerQuery("FILTERED_DATA = filter IP by $1 > 3;"); |
| 663 | pigServer.registerQuery("OP = stream FILTERED_DATA through CMD;"); |
| 664 | |
| 665 | String output = "/pig/out"; |
| 666 | pigServer.deleteFile(output); |
| 667 | pigServer.store("OP", output, PigStorage.class.getName() + "(',')"); |
| 668 | |
| 669 | pigServer.registerQuery("A = load '" + output + "/foobar" + "' using PigStorage(',');"); |
| 670 | Iterator<Tuple> iter = pigServer.openIterator("A"); |
| 671 | |
| 672 | List<Tuple> outputs = new ArrayList<Tuple>(); |
| 673 | while (iter.hasNext()) { |
| 674 | outputs.add(iter.next()); |
| 675 | } |
| 676 |
nothing calls this directly
no test coverage detected