You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2024/03/11 13:57:35 UTC

(kyuubi) branch master updated (6043dcc1b -> ca53942d1)

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

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


    omit 6043dcc1b [KYUUBI #6160] Fix beeline test KyuubiBeeLineTest.testKyuubiBeelineComment
     new ca53942d1 [KYUUBI #6160] Fix beeline test KyuubiBeeLineTest.testKyuubiBeelineComment

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (6043dcc1b)
            \
             N -- N -- N   refs/heads/master (ca53942d1)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java         | 5 +++++
 .../main/java/org/apache/hive/beeline/KyuubiDatabaseConnection.java  | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)


(kyuubi) 01/01: [KYUUBI #6160] Fix beeline test KyuubiBeeLineTest.testKyuubiBeelineComment

Posted by ch...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ca53942d13ca089fbfc471f3daa69bd1bc0c416a
Author: zhouyifan279 <zh...@gmail.com>
AuthorDate: Mon Mar 11 21:24:06 2024 +0800

    [KYUUBI #6160] Fix beeline test KyuubiBeeLineTest.testKyuubiBeelineComment
    
    # :mag: Description
    ## Issue References ๐Ÿ”—
    
    Shell command `beeline` uses `KyuubiBeeline#initArgs`, and never uses `KyuubiBeeline#initArgsFromCliVars`.
    We should replace `KyuubiBeeline#initArgsFromCliVars` with `KyuubiBeeline#initArgs` in test `KyuubiBeeLineTest#testKyuubiBeelineComment`.
    
    ## Describe Your Solution ๐Ÿ”ง
    
    ## Types of changes :bookmark:
    
    - [x] Bugfix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing functionality to change)
    
    ## Test Plan ๐Ÿงช
    
    #### Behavior Without This Pull Request :coffin:
    
    #### Behavior With This Pull Request :tada:
    
    #### Related Unit Tests
    
    ---
    
    # Checklist ๐Ÿ“
    
    - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html)
    
    **Be nice. Be informative.**
    
    Closes #6160 from zhouyifan279/beeline-comment-test.
    
    Closes #6160
    
    c250af07f [zhouyifan279] Fix beeline test KyuubiBeeLineTest.testKyuubiBeelineComment
    935aa371b [zhouyifan279] Fix flaky test KyuubiBeeLineTest.testKyuubiBeelineComment
    29bf670dd [zhouyifan279] Fix flaky test KyuubiBeeLineTest.testKyuubiBeelineComment
    f7a07425e [zhouyifan279] Fix flaky test KyuubiBeeLineTest.testKyuubiBeelineComment
    
    Authored-by: zhouyifan279 <zh...@gmail.com>
    Signed-off-by: Cheng Pan <ch...@apache.org>
---
 .../main/java/org/apache/hive/beeline/BeeLine.java |  6 ++-
 .../org/apache/hive/beeline/KyuubiBeeLine.java     | 12 ++---
 .../hive/beeline/KyuubiDatabaseConnection.java     |  2 +-
 .../org/apache/hive/beeline/KyuubiBeeLineTest.java | 54 ++++++++++++++++++----
 4 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/BeeLine.java b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/BeeLine.java
index e3b29206c..b66dca26c 100644
--- a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/BeeLine.java
+++ b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/BeeLine.java
@@ -134,7 +134,7 @@ public class BeeLine implements Closeable {
   private final BeeLineOpts opts = new BeeLineOpts(this, System.getProperties());
   private String lastProgress = null;
   private final Map<SQLWarning, Date> seenWarnings = new HashMap<SQLWarning, Date>();
-  private final Commands commands = new Commands(this);
+  private Commands commands = new Commands(this);
   private OutputFile scriptOutputFile = null;
   private OutputFile recordOutputFile = null;
   private PrintStream outputStream = new PrintStream(System.out, true);
@@ -2382,4 +2382,8 @@ public class BeeLine implements Closeable {
   boolean isTestMode() {
     return isTestMode;
   }
+
+  protected void setCommands(Commands commands) {
+    this.commands = commands;
+  }
 }
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 c786da35f..cba92f39f 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
@@ -48,7 +48,6 @@ public class KyuubiBeeLine extends BeeLine {
 
   public static final String KYUUBI_BEELINE_DEFAULT_JDBC_DRIVER =
       "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
-  protected KyuubiCommands commands = new KyuubiCommands(this);
   private Driver defaultDriver;
 
   // copied from org.apache.hive.beeline.BeeLine
@@ -66,11 +65,7 @@ public class KyuubiBeeLine extends BeeLine {
   @SuppressWarnings("deprecation")
   public KyuubiBeeLine(boolean isBeeLine) {
     super(isBeeLine);
-    try {
-      DynFields.builder().hiddenImpl(BeeLine.class, "commands").buildChecked(this).set(commands);
-    } catch (Throwable t) {
-      throw new ExceptionInInitializerError("Failed to inject kyuubi commands");
-    }
+    setCommands(new KyuubiCommands(this));
     try {
       defaultDriver =
           DynConstructors.builder()
@@ -299,4 +294,9 @@ public class KyuubiBeeLine extends BeeLine {
   boolean dispatch(String line) {
     return super.dispatch(isPythonMode() ? line : HiveStringUtils.removeComments(line));
   }
+
+  @Override
+  KyuubiCommands getCommands() {
+    return ((KyuubiCommands) super.getCommands());
+  }
 }
diff --git a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiDatabaseConnection.java b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiDatabaseConnection.java
index 83daaa8ad..dfa0a8cac 100644
--- a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiDatabaseConnection.java
+++ b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiDatabaseConnection.java
@@ -137,7 +137,7 @@ public class KyuubiDatabaseConnection extends DatabaseConnection {
     eventNotifier.progressBarCompleted();
 
     Thread logThread =
-        new Thread(beeLine.commands.createLogRunnable(kyuubiConnection, eventNotifier));
+        new Thread(beeLine.getCommands().createLogRunnable(kyuubiConnection, eventNotifier));
     logThread.setDaemon(true);
     logThread.start();
     kyuubiConnection.setEngineLogThread(logThread);
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 9c7aec35a..8b87b13a0 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
@@ -26,8 +26,13 @@ import java.io.OutputStream;
 import java.io.PrintStream;
 import org.apache.kyuubi.util.reflect.DynFields;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class KyuubiBeeLineTest {
+
+  private static final Logger LOG = LoggerFactory.getLogger(KyuubiBeeLineTest.class);
+
   @Test
   public void testKyuubiBeelineWithoutArgs() {
     KyuubiBeeLine kyuubiBeeLine = new KyuubiBeeLine();
@@ -90,15 +95,46 @@ public class KyuubiBeeLineTest {
 
   @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);
+    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);
+              return true;
+            }
+            return super.dispatch(line);
+          }
+        };
+
+    String[] cmd = new String[] {""};
+    KyuubiCommands interceptedCommands =
+        new KyuubiCommands(interceptedKyuubiBeeLine) {
+          @Override
+          public boolean sql(String line, boolean entireLineAsCommand) {
+            LOG.info("Return true for sql {} to pretend sql is executed successfully.", line);
+            cmd[0] = line;
+            return true;
+          }
+        };
+    interceptedKyuubiBeeLine.setCommands(interceptedCommands);
+
+    interceptedKyuubiBeeLine.initArgs(
+        new String[] {"-u", "dummy_url", "-e", "--comment show database;"});
+    assertEquals(0, cmd[0].length());
+
+    // 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]);
+
+    interceptedKyuubiBeeLine.setExit(false);
+    interceptedKyuubiBeeLine.initArgs(
+        new String[] {
+          "-u", "dummy_url", "-e", "--comment line 1 \n    --comment line 2 \n show database;"
+        });
+    assertEquals("show database;", cmd[0]);
   }
 
   static class BufferPrintStream extends PrintStream {