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

Method testInputCacheSpecs

test/org/apache/pig/test/TestStreaming.java:426–495  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

424 }
425
426 @Test
427 public void testInputCacheSpecs() throws Exception {
428 File input = Util.createInputFile("tmp", "",
429 new String[] {"A,1", "B,2", "C,3",
430 "D,2", "A,5", "B,5",
431 "C,8", "A,8", "D,8",
432 "A,9"});
433
434 // Perl script
435 String[] script =
436 new String[] {
437 "#!/usr/bin/perl",
438 "open(INFILE, $ARGV[0]) or die \"Can't open \".$ARGV[0].\"!: $!\";",
439 "while (<INFILE>) {",
440 " chomp $_;",
441 " print STDOUT \"$_\n\";",
442 " print STDERR \"STDERR: $_\n\";",
443 "}",
444 };
445 // Copy the scripts to HDFS
446 File command1 = Util.createInputFile("script", "pl", script);
447 File command2 = Util.createInputFile("script", "pl", script);
448 String c1 = FileLocalizer.hadoopify(command1.toString(),
449 pigServer.getPigContext());
450 String c2 = FileLocalizer.hadoopify(command2.toString(),
451 pigServer.getPigContext());
452
453 // Expected results
454 String[] expectedFirstFields =
455 new String[] {"A", "B", "C", "A", "D", "A"};
456 Integer[] expectedSecondFields = new Integer[] {5, 5, 8, 8, 8, 9};
457 Tuple[] expectedResults =
458 setupExpectedResults(Util.toDataByteArrays(expectedFirstFields),
459 Util.toDataByteArrays(expectedSecondFields));
460
461 // Pig query to run
462 pigServer.registerQuery(
463 "define CMD1 `perl script1.pl foo` " +
464 "cache ('" + c1 + "#script1.pl') " +
465 "input('foo' using " + PigStreaming.class.getName() + "(',')) " +
466 "stderr();");
467 pigServer.registerQuery(
468 "define CMD2 `perl script2.pl bar` " +
469 "cache ('" + c2 + "#script2.pl') " +
470 "input('bar' using " + PigStreaming.class.getName() + "(',')) " +
471 "stderr();");
472 pigServer.registerQuery("IP = load '"
473 + Util.generateURI(input.toString(),
474 pigServer.getPigContext()) + "' using "
475 + PigStorage.class.getName() + "(',');");
476 pigServer.registerQuery("FILTERED_DATA = filter IP by $1 > 3;");
477 pigServer.registerQuery("STREAMED_DATA = stream FILTERED_DATA " +
478 "through CMD1;");
479 pigServer.registerQuery("OP = stream STREAMED_DATA through CMD2;");
480
481 String output = "/pig/out";
482 pigServer.deleteFile(output);
483 pigServer.store("OP", output, PigStorage.class.getName() + "(',')");

Callers

nothing calls this directly

Calls 15

createInputFileMethod · 0.95
hadoopifyMethod · 0.95
setupExpectedResultsMethod · 0.95
toDataByteArraysMethod · 0.95
generateURIMethod · 0.95
checkQueryOutputsMethod · 0.95
openIteratorMethod · 0.80
addMethod · 0.65
iteratorMethod · 0.65
toStringMethod · 0.45
getPigContextMethod · 0.45
registerQueryMethod · 0.45

Tested by

no test coverage detected