Tests that Pig's Bzip2TextInputFormat throws an IOException when the input files to be loaded are actually a result of concatenating 2 or more bz2 files. It should not silently ignore part of the input data. When, hadoop's TextInpuFormat is used(PIG-3251), it should successfully read this concatena
()
| 578 | * successfully read this concatenated bzip file to the end. |
| 579 | */ |
| 580 | @Test |
| 581 | public void testBZ2Concatenation() throws Exception { |
| 582 | String[] inputData1 = new String[] { |
| 583 | "1\ta", |
| 584 | "2\taa" |
| 585 | }; |
| 586 | String[] inputData2 = new String[] { |
| 587 | "1\tb", |
| 588 | "2\tbb" |
| 589 | }; |
| 590 | String[] inputDataMerged = new String[] { |
| 591 | "1\ta", |
| 592 | "2\taa", |
| 593 | "1\tb", |
| 594 | "2\tbb" |
| 595 | }; |
| 596 | |
| 597 | // bzip compressed input file1 |
| 598 | File in1 = folder.newFile("junit-in1.bz2"); |
| 599 | String compressedInputFileName1 = in1.getAbsolutePath(); |
| 600 | |
| 601 | // file2 |
| 602 | File in2 = folder.newFile("junit-in2.bz2"); |
| 603 | String compressedInputFileName2 = in2.getAbsolutePath(); |
| 604 | |
| 605 | String unCompressedInputFileName = "testRecordDelims-uncomp.txt"; |
| 606 | Util.createInputFile(cluster, unCompressedInputFileName, inputDataMerged); |
| 607 | |
| 608 | try { |
| 609 | CBZip2OutputStream cos = |
| 610 | new CBZip2OutputStream(new FileOutputStream(in1)); |
| 611 | for (int i = 0; i < inputData1.length; i++) { |
| 612 | StringBuffer sb = new StringBuffer(); |
| 613 | sb.append(inputData1[i]).append("\n"); |
| 614 | byte bytes[] = sb.toString().getBytes(); |
| 615 | cos.write(bytes); |
| 616 | } |
| 617 | cos.close(); |
| 618 | |
| 619 | CBZip2OutputStream cos2 = |
| 620 | new CBZip2OutputStream(new FileOutputStream(in2)); |
| 621 | for (int i = 0; i < inputData2.length; i++) { |
| 622 | StringBuffer sb = new StringBuffer(); |
| 623 | sb.append(inputData2[i]).append("\n"); |
| 624 | byte bytes[] = sb.toString().getBytes(); |
| 625 | cos2.write(bytes); |
| 626 | } |
| 627 | cos2.close(); |
| 628 | |
| 629 | // cat |
| 630 | catInto(compressedInputFileName2, compressedInputFileName1); |
| 631 | Util.copyFromLocalToCluster(cluster, compressedInputFileName1, |
| 632 | compressedInputFileName1); |
| 633 | |
| 634 | // pig script to read uncompressed input |
| 635 | String script = "a = load '" + Util.encodeEscape(unCompressedInputFileName) +"';"; |
| 636 | PigServer pig = new PigServer(cluster.getExecType(), properties); |
| 637 | pig.registerQuery(script); |
nothing calls this directly
no test coverage detected