(String query, String expectedFile, PlanPrinter planPrinter)
| 140 | } |
| 141 | |
| 142 | private void run(String query, String expectedFile, PlanPrinter planPrinter) throws Exception { |
| 143 | PhysicalPlan pp = Util.buildPp(pigServer, query); |
| 144 | SparkLauncher launcher = new SparkLauncher(); |
| 145 | pc.inExplain = true; |
| 146 | SparkOperPlan sparkOperPlan = launcher.compile(pp, pc); |
| 147 | |
| 148 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 149 | PrintStream ps = new PrintStream(baos); |
| 150 | planPrinter.doPrint(ps, sparkOperPlan); |
| 151 | String compiledPlan = baos.toString(); |
| 152 | System.out.println(); |
| 153 | System.out.println("<<<" + compiledPlan + ">>>"); |
| 154 | |
| 155 | if (generate) { |
| 156 | FileOutputStream fos = new FileOutputStream(expectedFile); |
| 157 | fos.write(baos.toByteArray()); |
| 158 | fos.close(); |
| 159 | return; |
| 160 | } |
| 161 | FileInputStream fis = new FileInputStream(expectedFile); |
| 162 | byte[] b = new byte[MAX_SIZE]; |
| 163 | int len = fis.read(b); |
| 164 | fis.close(); |
| 165 | String goldenPlan = new String(b, 0, len); |
| 166 | if (goldenPlan.charAt(len-1) == '\n') { |
| 167 | goldenPlan = goldenPlan.substring(0, len-1); |
| 168 | } |
| 169 | |
| 170 | System.out.println("-------------"); |
| 171 | System.out.println("Golden"); |
| 172 | System.out.println("<<<" + goldenPlan + ">>>"); |
| 173 | System.out.println("-------------"); |
| 174 | |
| 175 | String goldenPlanClean = Util.standardizeNewline(goldenPlan).trim(); |
| 176 | String compiledPlanClean = Util.standardizeNewline(compiledPlan).trim(); |
| 177 | assertEquals(TestHelper.sortUDFs(Util.removeSignature(goldenPlanClean)), |
| 178 | TestHelper.sortUDFs(Util.removeSignature(compiledPlanClean))); |
| 179 | } |
| 180 | |
| 181 | } |
| 182 |
no test coverage detected