diff --git a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java index bcfa6944ea6..9498c1156fe 100644 --- a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java +++ b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java @@ -218,7 +218,7 @@ protected void processOption(String arg, ListIterator iter) throws ParseExceptio if (!commands.isEmpty()) { for (String command : commands) { debug(loc("executing-command", command)); - if (!dispatch(command)) { + if (!removeCommentsDispatch(command)) { code++; } } @@ -282,9 +282,8 @@ int runInit() { return executionResult; } - // see HIVE-15820: comment at the head of beeline -e - @Override - boolean dispatch(String line) { + // see HIVE-15820: comment at the head of beeline -e only dispatch commands + boolean removeCommentsDispatch(String line) { return super.dispatch(isPythonMode() ? line : HiveStringUtils.removeComments(line)); } diff --git a/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiBeeLineTest.java b/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiBeeLineTest.java index 8b87b13a06c..a58d9057c73 100644 --- a/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiBeeLineTest.java +++ b/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiBeeLineTest.java @@ -95,12 +95,14 @@ public void testKyuubiBeeLinePythonMode() { @Test public void testKyuubiBeelineComment() { + String[] url = new String[] {""}; KyuubiBeeLine interceptedKyuubiBeeLine = new KyuubiBeeLine() { @Override boolean dispatch(String line) { if (line != null && line.startsWith("!connect")) { LOG.info("Return true for command: {} to pretend connection is established.", line); + url[0] = line; return true; } return super.dispatch(line); @@ -122,12 +124,14 @@ public boolean sql(String line, boolean entireLineAsCommand) { interceptedKyuubiBeeLine.initArgs( new String[] {"-u", "dummy_url", "-e", "--comment show database;"}); assertEquals(0, cmd[0].length()); + assertEquals("!connect dummy_url '' '' ", url[0]); // Beeline#exit must be false to execute sql interceptedKyuubiBeeLine.setExit(false); interceptedKyuubiBeeLine.initArgs( new String[] {"-u", "dummy_url", "-e", "--comment\n show database;"}); assertEquals("show database;", cmd[0]); + assertEquals("!connect dummy_url '' '' ", url[0]); interceptedKyuubiBeeLine.setExit(false); interceptedKyuubiBeeLine.initArgs( @@ -135,6 +139,12 @@ public boolean sql(String line, boolean entireLineAsCommand) { "-u", "dummy_url", "-e", "--comment line 1 \n --comment line 2 \n show database;" }); assertEquals("show database;", cmd[0]); + + interceptedKyuubiBeeLine.setExit(false); + interceptedKyuubiBeeLine.initArgs( + new String[] {"-u", "dummy--url", "-e", "--comment\n show database;"}); + assertEquals("show database;", cmd[0]); + assertEquals("!connect dummy--url '' '' ", url[0]); } static class BufferPrintStream extends PrintStream {