This is an automated email from the ASF dual-hosted git repository.

feiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new e59349317 [KYUUBI #4305][Bug] Backport HIVE-15820: comment at the head 
of beeline -e
e59349317 is described below

commit e59349317f88abfb7f19cd63479f5f396bf05722
Author: fwang12 <[email protected]>
AuthorDate: Fri Jun 16 19:44:24 2023 +0800

    [KYUUBI #4305][Bug] Backport HIVE-15820: comment at the head of beeline -e
    
    ### _Why are the changes needed?_
    
    Backport https://github.com/apache/hive/pull/1814
    
    related kyuubi issues
    #4305
    #4333
    #4406
    
    ### _How was this patch tested?_
    - [x] Add some test cases that check the changes thoroughly including 
negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run 
test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests)
 locally before make a pull request
    
    Closes #4972 from turboFei/beeline_head_command.
    
    Closes #4305
    
    04b235fb3 [fwang12] [KYUUBI #4305][Bug] Backport HIVE-15820: comment at the 
head of beeline -e
    
    Authored-by: fwang12 <[email protected]>
    Signed-off-by: fwang12 <[email protected]>
---
 .../main/java/org/apache/hive/beeline/KyuubiBeeLine.java    |  7 +++++++
 .../main/java/org/apache/hive/beeline/KyuubiCommands.java   |  5 ++---
 .../java/org/apache/hive/beeline/KyuubiBeeLineTest.java     | 13 +++++++++++++
 .../java/org/apache/hive/beeline/KyuubiCommandsTest.java    |  8 ++++++++
 4 files changed, 30 insertions(+), 3 deletions(-)

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 e211d93e3..14e7de947 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
@@ -24,6 +24,7 @@ import java.util.*;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
+import org.apache.hive.common.util.HiveStringUtils;
 import org.apache.kyuubi.util.reflect.DynConstructors;
 import org.apache.kyuubi.util.reflect.DynFields;
 import org.apache.kyuubi.util.reflect.DynMethods;
@@ -275,4 +276,10 @@ public class KyuubiBeeLine extends BeeLine {
     }
     return executionResult;
   }
+
+  // see HIVE-15820: comment at the head of beeline -e
+  @Override
+  boolean dispatch(String line) {
+    return super.dispatch(isPythonMode() ? line : 
HiveStringUtils.removeComments(line));
+  }
 }
diff --git 
a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiCommands.java 
b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiCommands.java
index 6bd285962..af294ac6f 100644
--- 
a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiCommands.java
+++ 
b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiCommands.java
@@ -527,9 +527,8 @@ public class KyuubiCommands extends Commands {
             ? null
             : jline.console.ConsoleReader.NULL_MASK;
 
-    int[] startQuote = {-1};
     if (!beeLine.isPythonMode()) {
-      line = HiveStringUtils.removeComments(line, startQuote);
+      line = HiveStringUtils.removeComments(line);
     }
     while (isMultiLine(line) && beeLine.getOpts().isAllowMultiLineCommand()) {
       StringBuilder prompt = new StringBuilder(beeLine.getPrompt());
@@ -557,7 +556,7 @@ public class KyuubiCommands extends Commands {
         break;
       }
       if (!beeLine.isPythonMode()) {
-        extra = HiveStringUtils.removeComments(extra, startQuote);
+        extra = HiveStringUtils.removeComments(extra);
       }
       if (!extra.isEmpty()) {
         line += "\n" + extra;
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 87489f2ad..9c7aec35a 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
@@ -88,6 +88,19 @@ public class KyuubiBeeLineTest {
     kyuubiBeeLine.setPythonMode(false);
   }
 
+  @Test
+  public void testKyuubiBeelineComment() {
+    KyuubiBeeLine kyuubiBeeLine = new KyuubiBeeLine();
+    int result = kyuubiBeeLine.initArgsFromCliVars(new String[] {"-e", 
"--comment show database;"});
+    assertEquals(0, result);
+    result = kyuubiBeeLine.initArgsFromCliVars(new String[] {"-e", 
"--comment\n show database;"});
+    assertEquals(1, result);
+    result =
+        kyuubiBeeLine.initArgsFromCliVars(
+            new String[] {"-e", "--comment line 1 \n    --comment line 2 \n 
show database;"});
+    assertEquals(1, result);
+  }
+
   static class BufferPrintStream extends PrintStream {
     public StringBuilder stringBuilder = new StringBuilder();
 
diff --git 
a/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiCommandsTest.java
 
b/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiCommandsTest.java
index 8cde13d45..653d1b08f 100644
--- 
a/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiCommandsTest.java
+++ 
b/kyuubi-hive-beeline/src/test/java/org/apache/hive/beeline/KyuubiCommandsTest.java
@@ -59,5 +59,13 @@ public class KyuubiCommandsTest {
     assertEquals(cmdList.size(), 2);
     assertEquals(cmdList.get(0), "select 1");
     assertEquals(cmdList.get(1), "\nselect 2");
+
+    // see HIVE-15820: comment at the head of beeline -e
+    snippets = "--comments1\nselect 2;--comments2";
+    Mockito.when(reader.readLine()).thenReturn(snippets);
+    line = commands.handleMultiLineCmd(snippets);
+    cmdList = commands.getCmdList(line, false);
+    assertEquals(cmdList.size(), 1);
+    assertEquals(cmdList.get(0), "select 2");
   }
 }

Reply via email to