diff --git cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java index 4239392..d9b7031 100644 --- cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java +++ cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java @@ -32,12 +32,12 @@ import java.util.Set; import jline.ArgumentCompletor; +import jline.ArgumentCompletor.AbstractArgumentDelimiter; +import jline.ArgumentCompletor.ArgumentDelimiter; import jline.Completor; import jline.ConsoleReader; import jline.History; import jline.SimpleCompletor; -import jline.ArgumentCompletor.AbstractArgumentDelimiter; -import jline.ArgumentCompletor.ArgumentDelimiter; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -669,6 +669,30 @@ public static int run(String[] args) throws Exception { SessionState.start(ss); + // execute cli driver work + int ret = 0; + try { + ret = executeDriver(ss, conf, oproc); + } catch (Exception e) { + ss.close(); + throw e; + } + + ss.close(); + return ret; + } + + /** + * Execute the cli work + * @param ss CliSessionState of the CLI driver + * @param conf HiveConf for the driver sionssion + * @param oproc Opetion processor of the CLI invocation + * @return status of the CLI comman execution + * @throws Exception + */ + private static int executeDriver(CliSessionState ss, HiveConf conf, OptionsProcessor oproc) + throws Exception { + // connect to Hive Server if (ss.getHost() != null) { ss.connect(); @@ -704,12 +728,14 @@ public static int run(String[] args) throws Exception { cli.processInitFiles(ss); if (ss.execString != null) { - return cli.processLine(ss.execString); + int cmdProcessStatus = cli.processLine(ss.execString); + return cmdProcessStatus; } try { if (ss.fileName != null) { - return cli.processFile(ss.fileName); + int fileProcessStatus = cli.processFile(ss.fileName); + return fileProcessStatus; } } catch (FileNotFoundException e) { System.err.println("Could not open input file for reading. (" + e.getMessage() + ")"); @@ -764,9 +790,6 @@ public static int run(String[] args) throws Exception { continue; } } - - ss.close(); - return ret; } 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 8e6e24a..a6e87c4 100644 --- ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java +++ ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java @@ -22,16 +22,15 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; -import java.lang.management.ManagementFactory; import java.net.URI; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -303,9 +302,7 @@ public HiveHistory getHiveHistory() { * @return the unique string */ private static String makeSessionId() { - String userid = System.getProperty("user.name"); - return userid + "_" + ManagementFactory.getRuntimeMXBean().getName() + "_" - + DATE_FORMAT.format(new Date()); + return UUID.randomUUID().toString(); } /**