diff --git a/itests/qtest/pom.xml b/itests/qtest/pom.xml index 44d30da..07931b3 100644 --- a/itests/qtest/pom.xml +++ b/itests/qtest/pom.xml @@ -30,7 +30,7 @@ ../.. - + q_test_init.sql false @@ -437,7 +437,7 @@ logFile="${project.build.directory}/testclidrivergen.log" logDirectory="${project.build.directory}/qfile-results/clientpositive/" hadoopVersion="${active.hadoop.version}" - initScript="q_test_init.sql" + initScript="${initScript}" cleanupScript="q_test_cleanup.sql"/> diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java index 39d5d9e..b78f2a9 100644 --- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java +++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/QTestUtil.java @@ -121,8 +121,6 @@ private static final Log LOG = LogFactory.getLog("QTestUtil"); private static final String QTEST_LEAVE_FILES = "QTEST_LEAVE_FILES"; - private final String defaultInitScript = "q_test_init.sql"; - private final String defaultCleanupScript = "q_test_cleanup.sql"; private final String[] testOnlyCommands = new String[]{"crypto"}; private String testWarehouse; @@ -149,7 +147,6 @@ private HadoopShims.MiniMrShim mr = null; private HadoopShims.MiniDFSShim dfs = null; private HadoopShims.HdfsEncryptionShim hes = null; - private boolean miniMr = false; private String hadoopVer = null; private QTestSetup setup = null; private SparkSession sparkSession = null; @@ -209,7 +206,7 @@ public void copyDirectoryToLocal(Path src, Path dest) throws Exception { continue; } - if (file.isDir()) { + if (file.isDirectory()) { if (!destFs.exists(local_path)) { destFs.mkdirs(local_path); } @@ -410,14 +407,9 @@ public QTestUtil(String outDir, String logDir, MiniClusterType clusterType, if (scriptsDir == null) { scriptsDir = new File(".").getAbsolutePath() + "/data/scripts"; } - if (initScript.isEmpty()) { - initScript = defaultInitScript; - } - if (cleanupScript.isEmpty()) { - cleanupScript = defaultCleanupScript; - } - this.initScript = scriptsDir + "/" + initScript; - this.cleanupScript = scriptsDir + "/" + cleanupScript; + + this.initScript = scriptsDir + File.separator + initScript; + this.cleanupScript = scriptsDir + File.separator + cleanupScript; overWrite = "true".equalsIgnoreCase(System.getProperty("test.output.overwrite")); @@ -705,7 +697,7 @@ public void clearTablesCreatedDuringTests() throws Exception { FileSystem fileSystem = p.getFileSystem(conf); if (fileSystem.exists(p)) { for (FileStatus status : fileSystem.listStatus(p)) { - if (status.isDir() && !srcTables.contains(status.getPath().getName())) { + if (status.isDirectory() && !srcTables.contains(status.getPath().getName())) { fileSystem.delete(status.getPath(), true); } } @@ -755,16 +747,19 @@ public void cleanUp() throws Exception { clearTablesCreatedDuringTests(); clearKeysCreatedInTests(); - SessionState.get().getConf().setBoolean("hive.test.shutdown.phase", true); - - String cleanupCommands = readEntireFileIntoString(new File(cleanupScript)); - LOG.info("Cleanup (" + cleanupScript + "):\n" + cleanupCommands); - if(cliDriver == null) { - cliDriver = new CliDriver(); + File cleanupFile = new File(cleanupScript); + if (cleanupFile.isFile()) { + String cleanupCommands = readEntireFileIntoString(cleanupFile); + LOG.info("Cleanup (" + cleanupScript + "):\n" + cleanupCommands); + if(cliDriver == null) { + cliDriver = new CliDriver(); + } + SessionState.get().getConf().setBoolean("hive.test.shutdown.phase", true); + cliDriver.processLine(cleanupCommands); + SessionState.get().getConf().setBoolean("hive.test.shutdown.phase", false); + } else { + LOG.info("No cleanup script detected. Skipping."); } - cliDriver.processLine(cleanupCommands); - - SessionState.get().getConf().setBoolean("hive.test.shutdown.phase", false); // delete any contents in the warehouse dir Path p = new Path(testWarehouse); @@ -809,14 +804,21 @@ public void createSources() throws Exception { if(!isSessionStateStarted) { startSessionState(); } - conf.setBoolean("hive.test.init.phase", true); - String initCommands = readEntireFileIntoString(new File(this.initScript)); - LOG.info("Initial setup (" + initScript + "):\n" + initCommands); if(cliDriver == null) { cliDriver = new CliDriver(); } cliDriver.processLine("set test.data.dir=" + testFiles + ";"); + File scriptFile = new File(this.initScript); + if (!scriptFile.isFile()) { + LOG.info("No init script detected. Skipping"); + return; + } + conf.setBoolean("hive.test.init.phase", true); + + String initCommands = readEntireFileIntoString(scriptFile); + LOG.info("Initial setup (" + initScript + "):\n" + initCommands); + cliDriver.processLine(initCommands); conf.setBoolean("hive.test.init.phase", false); @@ -912,6 +914,7 @@ public String cliInit(String tname, boolean recreate) throws Exception { private CliSessionState createSessionState() { return new CliSessionState(conf) { + @Override public void setSparkSession(SparkSession sparkSession) { super.setSparkSession(sparkSession); if (sparkSession != null) { @@ -1136,11 +1139,6 @@ private String getCommand(String tname) { return commands; } - private boolean isComment(final String line) { - String lineTrimmed = line.trim(); - return lineTrimmed.startsWith("#") || lineTrimmed.startsWith("--"); - } - public boolean shouldBeSkipped(String tname) { return qSkipSet.contains(tname); }