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

Method testBZ2Concatenation

test/org/apache/pig/test/TestBZip.java:580–669  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 15

createInputFileMethod · 0.95
writeMethod · 0.95
closeMethod · 0.95
catIntoMethod · 0.95
encodeEscapeMethod · 0.95
registerQueryMethod · 0.95
openIteratorMethod · 0.95
deleteFileMethod · 0.95
getAbsolutePathMethod · 0.80
getPropertyMethod · 0.80
appendMethod · 0.65

Tested by

no test coverage detected