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 2365fb7..f64ffa3 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 @@ -39,6 +39,8 @@ import java.io.UnsupportedEncodingException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; @@ -1986,7 +1988,7 @@ public void preTest(HiveConf conf) throws Exception { if (zooKeeperCluster == null) { //create temp dir String tmpBaseDir = System.getProperty(TEST_TMP_DIR_PROPERTY); - File tmpDir = Utilities.createTempDir(tmpBaseDir); + File tmpDir = Files.createTempDirectory(Paths.get(tmpBaseDir), "tmp_").toFile(); zooKeeperCluster = new MiniZooKeeperCluster(); zkPort = zooKeeperCluster.startup(tmpDir); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index 2177c33..9944d9e 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -3758,32 +3758,6 @@ public static void clearWorkMap(Configuration conf) { } /** - * Create a temp dir in specified baseDir - * This can go away once hive moves to support only JDK 7 - * and can use Files.createTempDirectory - * Guava Files.createTempDir() does not take a base dir - * @param baseDir - directory under which new temp dir will be created - * @return File object for new temp dir - */ - public static File createTempDir(String baseDir){ - //try creating the temp dir MAX_ATTEMPTS times - final int MAX_ATTEMPS = 30; - for(int i = 0; i < MAX_ATTEMPS; i++){ - //pick a random file name - String tempDirName = "tmp_" + ((int)(100000 * Math.random())); - - //return if dir could successfully be created with that file name - File tempDir = new File(baseDir, tempDirName); - if(tempDir.mkdir()){ - return tempDir; - } - } - throw new IllegalStateException("Failed to create a temp dir under " - + baseDir + " Giving up after " + MAX_ATTEMPS + " attempts"); - - } - - /** * Skip header lines in the table file when reading the record. * * @param currRecReader