diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index 11ff3f2..28a75e2 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -445,7 +445,7 @@ String loc(String res, Object param1) { } String loc(String res, Object param1, Object param2) { - return loc(res, new Object[] {param1, param2}); + return loc(res, new Object[] { param1, param2 }); } String loc(String res, Object[] params) { @@ -880,8 +880,13 @@ int runInit() { return ERRNO_OK; } + /** + * Used for connecting the embedded hive server2 for new CLI mode + * + * @return + */ private int embeddedConnect() { - if (!dispatch("!connect " + Utils.URL_PREFIX + " '' ''")) { + if (!dispatch("!connect " + Utils.URL_PREFIX + " '' ''", true)) { return ERRNO_OTHER; } else { return ERRNO_OK; @@ -897,6 +902,12 @@ private int connectDBInEmbededMode() { return ERRNO_OK; } + /** + * This is used for new CLI mode. + * + * @param exitOnError + * @return + */ public int defaultConnect(boolean exitOnError) { if (embeddedConnect() != ERRNO_OK && exitOnError) { return ERRNO_OTHER; @@ -1103,6 +1114,17 @@ public boolean execCommandWithPrefix(String line) { * @return true if the command was "successful" */ boolean dispatch(String line) { + return dispatch(line, false); + } + + /** + * Dispatch the specified line to the appropriate {@link CommandHandler}. + * + * @param line the command-line to dispatch + * @param isInternal Command like "!connect" can be only used internally for new CLI mode. + * @return true if the command was "successful" + */ + boolean dispatch(String line, boolean isInternal) { if (line == null) { // exit exit = true; @@ -1136,7 +1158,7 @@ boolean dispatch(String line) { return commands.sql(line, getOpts().getEntireLineAsCommand()); } } else { - if (line.toLowerCase().startsWith("!connect")) { + if (line.toLowerCase().startsWith("!connect") && isInternal) { return execCommandWithPrefix(line); } else { return commands.sql(line, getOpts().getEntireLineAsCommand());