()
| 61 | } |
| 62 | |
| 63 | @Test |
| 64 | public void testMapOnly() throws IOException, ExecException { |
| 65 | int count = 0; |
| 66 | PrintWriter pw = new PrintWriter(Util.createInputFile(cluster, file)); |
| 67 | for(int i = 0; i < MAX; i++) { |
| 68 | int t = r.nextInt(100); |
| 69 | pw.println(t); |
| 70 | if(t > 50) count ++; |
| 71 | } |
| 72 | pw.close(); |
| 73 | PigServer pigServer = new PigServer(cluster.getExecType(), cluster.getProperties()); |
| 74 | pigServer.registerQuery("a = load '" + file + "';"); |
| 75 | pigServer.registerQuery("b = filter a by $0 > 50;"); |
| 76 | pigServer.registerQuery("c = foreach b generate $0 - 50;"); |
| 77 | ExecJob job = pigServer.store("c", "output_map_only"); |
| 78 | PigStats pigStats = job.getStatistics(); |
| 79 | |
| 80 | //counting the no. of bytes in the output file |
| 81 | //long filesize = cluster.getFileSystem().getFileStatus(new Path("output_map_only")).getLen(); |
| 82 | InputStream is = FileLocalizer.open(FileLocalizer.fullPath( |
| 83 | "output_map_only", pigServer.getPigContext()), pigServer |
| 84 | .getPigContext()); |
| 85 | |
| 86 | long filesize = 0; |
| 87 | while(is.read() != -1) filesize++; |
| 88 | |
| 89 | is.close(); |
| 90 | |
| 91 | cluster.getFileSystem().delete(new Path(file), true); |
| 92 | cluster.getFileSystem().delete(new Path("output_map_only"), true); |
| 93 | |
| 94 | System.out.println("============================================"); |
| 95 | System.out.println("Test case Map Only"); |
| 96 | System.out.println("============================================"); |
| 97 | |
| 98 | JobGraph jg = pigStats.getJobGraph(); |
| 99 | Iterator<JobStats> iter = jg.iterator(); |
| 100 | while (iter.hasNext()) { |
| 101 | JobStats js = iter.next(); |
| 102 | |
| 103 | System.out.println("Map input records : " + js.getMapInputRecords()); |
| 104 | assertEquals(MAX, js.getMapInputRecords()); |
| 105 | System.out.println("Map output records : " + js.getMapOutputRecords()); |
| 106 | assertEquals(count, js.getMapOutputRecords()); |
| 107 | assertEquals(0, js.getReduceInputRecords()); |
| 108 | assertEquals(0, js.getReduceOutputRecords()); |
| 109 | System.out.println("Hdfs bytes written : " + js.getHdfsBytesWritten()); |
| 110 | assertEquals(filesize, js.getHdfsBytesWritten()); |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | @Test |
| 116 | public void testMapOnlyBinStorage() throws IOException, ExecException { |
nothing calls this directly
no test coverage detected