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

fchen pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


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

commit e5592f547eaefa7addd8f0e4af2817df23abc5d2
Author: senmiaoliu <[email protected]>
AuthorDate: Thu Feb 16 17:05:18 2023 +0800

    [KYUUBI #4305][Bug] Backport HIVE-15820: comment at the head of beeline -e
    
    ### _Why are the changes needed?_
    
    close [#4305](https://github.com/apache/kyuubi/issues/4305)
    
    ### manual tests
    
    ```sql
    bin/beeline -u jdbc:hive2://X:10009 -e "
    --asd
    select 1 as a
    "
    ```
    
    
![image](https://user-images.githubusercontent.com/18713676/218910222-b829d447-e5b7-4d80-842b-2ddd4f47a26d.png)
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including 
negative and positive cases if possible
    
    - [x] Add screenshots for manual tests if appropriate
    
    - [ ] [Run 
test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests)
 locally before make a pull request
    
    Closes #4333 from lsm1/fix/beeline_comment_header.
    
    Closes #4305
    
    f932d4ead [senmiaoliu] reformat
    9a071fb40 [senmiaoliu] added multi line ut
    425c53631 [senmiaoliu] added ut
    d4dc21a61 [senmiaoliu] comment at the head of beeline -e
    
    Authored-by: senmiaoliu <[email protected]>
    Signed-off-by: Fu Chen <[email protected]>
    (cherry picked from commit c489e29697c73e3eec96aa3ff602e40f9a2c798a)
    Signed-off-by: Fu Chen <[email protected]>
---
 .../main/java/org/apache/hive/beeline/KyuubiBeeLine.java    |  6 ++++++
 .../main/java/org/apache/hive/beeline/KyuubiCommands.java   |  6 ++++--
 .../java/org/apache/hive/beeline/KyuubiBeeLineTest.java     | 13 +++++++++++++
 3 files changed, 23 insertions(+), 2 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 7ca767148..92b96ccb4 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
@@ -29,6 +29,7 @@ import java.util.List;
 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;
 
 public class KyuubiBeeLine extends BeeLine {
   public static final String KYUUBI_BEELINE_DEFAULT_JDBC_DRIVER =
@@ -192,4 +193,9 @@ public class KyuubiBeeLine extends BeeLine {
     }
     return code;
   }
+
+  @Override
+  boolean dispatch(String line) {
+    return super.dispatch(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 aaa32739a..1a15638f1 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
@@ -23,6 +23,7 @@ import java.io.*;
 import java.sql.*;
 import java.util.*;
 import org.apache.hive.beeline.logs.KyuubiBeelineInPlaceUpdateStream;
+import org.apache.hive.common.util.HiveStringUtils;
 import org.apache.kyuubi.jdbc.hive.KyuubiStatement;
 import org.apache.kyuubi.jdbc.hive.Utils;
 import org.apache.kyuubi.jdbc.hive.logs.InPlaceUpdateStream;
@@ -499,7 +500,7 @@ public class KyuubiCommands extends Commands {
 
   @Override
   public String handleMultiLineCmd(String line) throws IOException {
-    int[] startQuote = {-1};
+    line = HiveStringUtils.removeComments(line);
     Character mask =
         (System.getProperty("jline.terminal", 
"").equals("jline.UnsupportedTerminal"))
             ? null
@@ -530,7 +531,8 @@ public class KyuubiCommands extends Commands {
       if (extra == null) { // it happens when using -f and the line of cmds 
does not end with ;
         break;
       }
-      if (!extra.isEmpty()) {
+      extra = HiveStringUtils.removeComments(extra);
+      if (extra != null && !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 b144c95c6..d571d9362 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
@@ -29,4 +29,17 @@ public class KyuubiBeeLineTest {
     int result = kyuubiBeeLine.initArgs(new String[0]);
     assertEquals(0, result);
   }
+
+  @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);
+  }
 }

Reply via email to