diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index 9c50e02..46d1a88 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -699,7 +699,7 @@ int initArgsFromCliVars(String[] args) { for (Iterator i = commands.iterator(); i.hasNext(); ) { String command = i.next().toString(); debug(loc("executing-command", command)); - if (!dispatch(command)) { + if (!dispatch(command, true)) { code++; } } @@ -776,12 +776,12 @@ int initArgs(String[] args) { + (pass == null || pass.length() == 0 ? "''" : pass) + " " + (driver == null ? "" : driver); debug("issuing: " + com); - dispatch(com); + dispatch(com, true); } // now load properties files - for (Iterator i = files.iterator(); i.hasNext();) { - dispatch("!properties " + i.next()); + for (Iterator i = files.iterator(); i.hasNext(); ) { + dispatch("!properties " + i.next(), true); } int code = 0; @@ -789,7 +789,7 @@ int initArgs(String[] args) { for (Iterator i = commands.iterator(); i.hasNext();) { String command = i.next().toString(); debug(loc("executing-command", command)); - if (!dispatch(command)) { + if (!dispatch(command, true)) { code++; } } @@ -881,7 +881,7 @@ int runInit() { } private int embeddedConnect() { - if (!dispatch("!connect " + Utils.URL_PREFIX + " '' ''")) { + if (!dispatch("!connect " + Utils.URL_PREFIX + " '' ''", false)) { return ERRNO_OTHER; } else { return ERRNO_OK; @@ -890,7 +890,7 @@ private int embeddedConnect() { private int connectDBInEmbededMode() { if (dbName != null && !dbName.isEmpty()) { - if (!dispatch("use " + dbName + ";")) { + if (!dispatch("use " + dbName + ";", false)) { return ERRNO_OTHER; } } @@ -965,7 +965,7 @@ private int execute(ConsoleReader reader, boolean exitOnError) { // trim line line = (line == null) ? null : line.trim(); - if (!dispatch(line) && exitOnError) { + if (!dispatch(line, true) && exitOnError) { return ERRNO_OTHER; } } catch (Throwable t) { @@ -1077,11 +1077,7 @@ public boolean execCommandWithPrefix(String line) { for (int i = 0; i < commandHandlers.length; i++) { String match = commandHandlers[i].matches(line); if (match != null) { - CommandHandler prev = cmdMap.put(match, commandHandlers[i]); - if (prev != null) { - return error( - loc("multiple-matches", Arrays.asList(prev.getName(), commandHandlers[i].getName()))); - } + cmdMap.put(match, commandHandlers[i]); } } @@ -1104,9 +1100,11 @@ public boolean execCommandWithPrefix(String line) { * * @param line * the command-line to dispatch + * @param isFromConsole + * whether the command is from console. * @return true if the command was "successful" */ - boolean dispatch(String line) { + boolean dispatch(String line, boolean isFromConsole) { if (line == null) { // exit exit = true; @@ -1140,7 +1138,8 @@ boolean dispatch(String line) { return commands.sql(line, getOpts().getEntireLineAsCommand()); } } else { - if (line.toLowerCase().startsWith("!connect")) { + // In hive cli mode, connect command can be used only internally. + if (line.toLowerCase().startsWith("!connect") && !isFromConsole) { return execCommandWithPrefix(line); } else { return commands.sql(line, getOpts().getEntireLineAsCommand()); @@ -2059,7 +2058,7 @@ public int runCommands(List cmds) { info(getColorBuffer().pad(SCRIPT_OUTPUT_PREFIX, SCRIPT_OUTPUT_PAD_SIZE).append(cmd)); // if we do not force script execution, abort // when a failure occurs. - if (dispatch(cmd) || getOpts().getForce()) { + if (dispatch(cmd, true) || getOpts().getForce()) { ++successCount; } else { error(loc("abort-on-error", cmd)); diff --git a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java index 702805f..ff904de 100644 --- a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java +++ b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java @@ -66,7 +66,7 @@ public TestBeelineArgParsing(String connectionString, String driverClazzName, St List queries = new ArrayList(); @Override - boolean dispatch(String command) { + boolean dispatch(String command, boolean isFromConsole) { String connectCommand = "!connect"; String propertyCommand = "!property"; if (command.startsWith(connectCommand)) {