(String query, String expectedFile)
| 1371 | } |
| 1372 | |
| 1373 | private void run(String query, String expectedFile) throws Exception { |
| 1374 | PhysicalPlan pp = Util.buildPp(pigServer, query); |
| 1375 | TezLauncher launcher = new TezLauncher(); |
| 1376 | pc.inExplain = true; |
| 1377 | TezPlanContainer tezPlanContainer = launcher.compile(pp, pc); |
| 1378 | |
| 1379 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 1380 | PrintStream ps = new PrintStream(baos); |
| 1381 | TezPlanContainerPrinter printer = new TezPlanContainerPrinter(ps, tezPlanContainer); |
| 1382 | printer.visit(); |
| 1383 | String compiledPlan = baos.toString(); |
| 1384 | System.out.println(); |
| 1385 | System.out.println("<<<" + compiledPlan + ">>>"); |
| 1386 | |
| 1387 | if (generate) { |
| 1388 | FileOutputStream fos = new FileOutputStream(expectedFile); |
| 1389 | fos.write(baos.toByteArray()); |
| 1390 | fos.close(); |
| 1391 | return; |
| 1392 | } |
| 1393 | FileInputStream fis = new FileInputStream(expectedFile); |
| 1394 | byte[] b = new byte[MAX_SIZE]; |
| 1395 | int len = fis.read(b); |
| 1396 | fis.close(); |
| 1397 | String goldenPlan = new String(b, 0, len); |
| 1398 | if (goldenPlan.charAt(len-1) == '\n') { |
| 1399 | goldenPlan = goldenPlan.substring(0, len-1); |
| 1400 | } |
| 1401 | |
| 1402 | System.out.println("-------------"); |
| 1403 | System.out.println("Golden"); |
| 1404 | System.out.println("<<<" + goldenPlan + ">>>"); |
| 1405 | System.out.println("-------------"); |
| 1406 | |
| 1407 | String goldenPlanClean = Util.standardizeNewline(goldenPlan).trim(); |
| 1408 | String compiledPlanClean = Util.standardizeNewline(compiledPlan).trim(); |
| 1409 | assertEquals(TestHelper.sortUDFs(Util.removeSignature(goldenPlanClean)), |
| 1410 | TestHelper.sortUDFs(Util.removeSignature(compiledPlanClean))); |
| 1411 | } |
| 1412 | |
| 1413 | public static class TestDummyStoreFunc extends StoreFunc { |
| 1414 |
no test coverage detected