diff --git ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java index 9f76dbe..0e8fa11 100644 --- ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java +++ ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java @@ -602,14 +602,26 @@ public class SessionState { private String downloadResource(String value, boolean convertToUnix) { if (canDownloadResource(value)) { getConsole().printInfo("converting to local " + value); - File resourceDir = new File(getConf().getVar(HiveConf.ConfVars.DOWNLOADED_RESOURCES_DIR)); + String location = getConf().getVar(HiveConf.ConfVars.DOWNLOADED_RESOURCES_DIR); String destinationName = new Path(value).getName(); - File destinationFile = new File(resourceDir, destinationName); - if ( resourceDir.exists() && ! resourceDir.isDirectory() ) { - throw new RuntimeException("The resource directory is not a directory, resourceDir is set to" + resourceDir); - } - if ( ! resourceDir.exists() && ! resourceDir.mkdirs() ) { - throw new RuntimeException("Couldn't create directory " + resourceDir); + + File destinationFile; + if (!location.equals("temporary")) { + File resourceDir = new File(location); + if (resourceDir.exists() && !resourceDir.isDirectory()) { + throw new RuntimeException("The resource directory is not a directory, " + + "resourceDir is set to " + resourceDir); + } + if (!resourceDir.exists() && !resourceDir.mkdirs()) { + throw new RuntimeException("Couldn't create directory " + resourceDir); + } + destinationFile = new File(resourceDir, destinationName); + } else { + try { + destinationFile = File.createTempFile(destinationName, null); + } catch (Exception e) { + throw new RuntimeException("Failed to create temporary file for " + value, e); + } } try { FileSystem fs = FileSystem.get(new URI(value), conf); @@ -619,7 +631,8 @@ public class SessionState { try { DosToUnix.convertWindowsScriptToUnix(destinationFile); } catch (Exception e) { - throw new RuntimeException("Caught exception while converting to unix line endings", e); + throw new RuntimeException("Caught exception while converting " + + "to unix line endings", e); } } } catch (Exception e) {