PigServer pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
pigServer.registerQuery("a = load '" + file + "';");
pigServer.registerQuery("b = group a by $0;");
pigServer.registerQuery("c = foreach b generate group, SUM(a.$1);");
PigStats pigStats = pigServer.store("c", "output", "BinStorage").getStatistics();
InputStream is = FileLocalizer.open(FileLocalizer.fullPath("output", pigServer.getPigContext()), ExecType.MAPREDUCE, pigServer.getPigContext().getDfs());
long filesize = 0;
while(is.read() != -1) filesize++;
is.close();
Map<String, Map<String, String>> stats = pigStats.getPigStats();
cluster.getFileSystem().delete(new Path(file), true);
cluster.getFileSystem().delete(new Path("output"), true);
System.out.println("============================================");
System.out.println("Test case MapCombineReduce");
System.out.println("============================================");
System.out.println("MRPlan : \n" + pigStats.getMRPlan());
for(Map.Entry<String, Map<String, String>> entry : stats.entrySet()) {
System.out.println("============================================");
System.out.println("Job : " + entry.getKey());
for(Map.Entry<String, String> e1 : entry.getValue().entrySet()) {
System.out.println(" - " + e1.getKey() + " : \n" + e1.getValue());
}
System.out.println("============================================");
}
Map.Entry<String, Map<String, String>> e = stats.entrySet().iterator().next();
Map<String, String> jobStats = e.getValue();
System.out.println("Map input records : " + jobStats.get("PIG_STATS_MAP_INPUT_RECORDS"));
assertEquals(MAX, Integer.parseInt(jobStats.get("PIG_STATS_MAP_INPUT_RECORDS")));
System.out.println("Map output records : " + jobStats.get("PIG_STATS_MAP_OUTPUT_RECORDS"));
assertEquals(MAX, Integer.parseInt(jobStats.get("PIG_STATS_MAP_OUTPUT_RECORDS")));
System.out.println("Reduce input records : " + jobStats.get("PIG_STATS_REDUCE_INPUT_RECORDS"));
assertEquals(count, Integer.parseInt(jobStats.get("PIG_STATS_REDUCE_INPUT_RECORDS")));
System.out.println("Reduce output records : " + jobStats.get("PIG_STATS_REDUCE_OUTPUT_RECORDS"));
assertEquals(count, Integer.parseInt(jobStats.get("PIG_STATS_REDUCE_OUTPUT_RECORDS")));
assertNotNull(jobStats.get("PIG_STATS_COMBINE_PLAN"));
assertNotNull(jobStats.get("PIG_STATS_MAP_PLAN"));
assertNotNull(jobStats.get("PIG_STATS_REDUCE_PLAN"));
assertEquals(count, pigStats.getRecordsWritten());
assertEquals(filesize, pigStats.getBytesWritten());
}