commit e76c1be4c83231bc2a7c456f360db02835b6550e Author: Vihang Karajgaonkar Date: Wed Sep 7 21:18:24 2016 -0700 HIVE-14717 : Beeline tests failing diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index ecd60f6c1a7583a413562a08f9eb3bebfc9b2759..739f989a020680179a3aee1c2b7cd8aab7950edf 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -84,6 +84,7 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; @@ -316,11 +317,13 @@ .create('n')); // -p - options.addOption(OptionBuilder + Option passwordOption = OptionBuilder .hasArg() .withArgName("password") .withDescription("the password to connect as") - .create('p')); + .create('p'); + passwordOption.setOptionalArg(true); + options.addOption(passwordOption); // -w (or) --password-file options.addOption(OptionBuilder @@ -727,7 +730,7 @@ int initArgs(String[] args) { return -1; } - String driver = null, user = null, pass = null, url = null; + String driver = null, user = null, pass = "", url = null; String auth = null; @@ -754,7 +757,9 @@ int initArgs(String[] args) { if (cl.hasOption("w")) { pass = obtainPasswordFromFile(cl.getOptionValue("w")); } else { - pass = cl.getOptionValue("p"); + if (cl.hasOption("p")) { + pass = cl.getOptionValue("p"); + } } url = cl.getOptionValue("u"); if ((url == null) && cl.hasOption("reconnect")){ @@ -834,16 +839,20 @@ private void setHiveConfVar(String key, String val) { } private String constructCmd(String url, String user, String pass, String driver, boolean stripPasswd) { - String com = "!connect " - + url + " " - + (user == null || user.length() == 0 ? "''" : user) + " "; - if (stripPasswd) { - com += PASSWD_MASK + " "; - } else { - com += (pass == null || pass.length() == 0 ? "''" : pass) + " "; + StringBuilder command = new StringBuilder("!connect "); + command.append(url + " "); + command.append((user == null || user.length() == 0 ? "''" : user) + " "); + if(stripPasswd) { + command.append(PASSWD_MASK + " "); + } else if(pass != null) { + if(pass.length() == 0) { + command.append("'' "); + } else { + command.append(pass + " "); + } } - com += (driver == null ? "" : driver); - return com; + command.append((driver == null ? "" : driver)); + return command.toString(); } /** * Obtains a password from the passed file path. @@ -881,6 +890,8 @@ public int begin(String[] args, InputStream inputStream) throws IOException { } try { + ConsoleReader reader = getConsoleReader(inputStream); + setConsoleReader(reader); if (isBeeLine) { int code = initArgs(args); if (code != 0) { @@ -905,7 +916,6 @@ public int begin(String[] args, InputStream inputStream) throws IOException { } catch (Exception e) { // ignore } - ConsoleReader reader = getConsoleReader(inputStream); return execute(reader, false); } finally { close();