You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by fe...@apache.org on 2023/03/27 09:17:02 UTC

[kyuubi] branch master updated: [KYUUBI #4609] get engineRefId in KyuubiConnection

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 6fd3353c7 [KYUUBI #4609] get engineRefId in KyuubiConnection
6fd3353c7 is described below

commit 6fd3353c780e50c9129fbebe849b19424450476d
Author: Tianlin Liao <ti...@ebay.com>
AuthorDate: Mon Mar 27 17:16:52 2023 +0800

    [KYUUBI #4609] get engineRefId in KyuubiConnection
    
    ### _Why are the changes needed?_
    
    Close #4609
    ### _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
    
    - [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #4610 from lightning-L/kyuubi-4609.
    
    Closes #4609
    
    c40fd71ed [Tianlin Liao] fix test case
    8f2d96cf0 [Tianlin Liao] [KYUUBI #4609] get engineRefId in KyuubiConnection
    
    Authored-by: Tianlin Liao <ti...@ebay.com>
    Signed-off-by: fwang12 <fw...@ebay.com>
---
 .../main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java    | 7 +++++++
 .../src/main/scala/org/apache/kyuubi/engine/EngineRef.scala        | 2 ++
 .../org/apache/kyuubi/operation/KyuubiApplicationOperation.scala   | 6 +++++-
 .../src/main/scala/org/apache/kyuubi/operation/LaunchEngine.scala  | 5 +++++
 .../kyuubi/operation/KyuubiOperationPerConnectionSuite.scala       | 1 +
 .../scala/org/apache/kyuubi/server/BackendServiceMetricSuite.scala | 2 +-
 6 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
index 2a485b24e..f9935d23e 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
@@ -107,6 +107,7 @@ public class KyuubiConnection implements SQLConnection, KyuubiLoggable {
   private String engineId = "";
   private String engineName = "";
   private String engineUrl = "";
+  private String engineRefId = "";
 
   private boolean isBeeLineMode;
 
@@ -1370,6 +1371,8 @@ public class KyuubiConnection implements SQLConnection, KyuubiLoggable {
           engineName = value;
         } else if ("url".equals(key)) {
           engineUrl = value;
+        } else if ("refId".equals(key)) {
+          engineRefId = value;
         }
       }
     } catch (Exception e) {
@@ -1388,4 +1391,8 @@ public class KyuubiConnection implements SQLConnection, KyuubiLoggable {
   public String getEngineUrl() {
     return engineUrl;
   }
+
+  public String getEngineRefId() {
+    return engineRefId;
+  }
 }
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/EngineRef.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/EngineRef.scala
index 5f3af28f8..63b37f1c5 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/EngineRef.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/EngineRef.scala
@@ -85,6 +85,8 @@ private[kyuubi] class EngineRef(
 
   private var builder: ProcBuilder = _
 
+  private[kyuubi] def getEngineRefId(): String = engineRefId
+
   // Launcher of the engine
   private[kyuubi] val appUser: String = shareLevel match {
     case SERVER => Utils.currentUser
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiApplicationOperation.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiApplicationOperation.scala
index b864f0101..605c4cca6 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiApplicationOperation.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/KyuubiApplicationOperation.scala
@@ -33,6 +33,10 @@ abstract class KyuubiApplicationOperation(session: Session) extends KyuubiOperat
 
   protected def currentApplicationInfo: Option[ApplicationInfo]
 
+  protected def applicationInfoMap: Option[Map[String, String]] = {
+    currentApplicationInfo.map(_.toMap)
+  }
+
   override def getResultSetMetadata: TGetResultSetMetadataResp = {
     val schema = new TTableSchema()
     Seq("key", "value").zipWithIndex.foreach { case (colName, position) =>
@@ -51,7 +55,7 @@ abstract class KyuubiApplicationOperation(session: Session) extends KyuubiOperat
   }
 
   override def getNextRowSet(order: FetchOrientation, rowSetSize: Int): TRowSet = {
-    currentApplicationInfo.map(_.toMap).map { state =>
+    applicationInfoMap.map { state =>
       val tRow = new TRowSet(0, new JArrayList[TRow](state.size))
       Seq(state.keys, state.values.map(Option(_).getOrElse(""))).map(_.toSeq.asJava).foreach {
         col =>
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/LaunchEngine.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/LaunchEngine.scala
index 3d9b4937f..fb4f39e26 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/LaunchEngine.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/operation/LaunchEngine.scala
@@ -68,4 +68,9 @@ class LaunchEngine(session: KyuubiSessionImpl, override val shouldRunAsync: Bool
 
     if (!shouldRunAsync) getBackgroundHandle.get()
   }
+
+  override protected def applicationInfoMap: Option[Map[String, String]] = {
+    super.applicationInfoMap.map { _ + ("refId" -> session.engine.getEngineRefId()) }
+  }
+
 }
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala
index 669475b6c..d04afbfb5 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala
@@ -137,6 +137,7 @@ class KyuubiOperationPerConnectionSuite extends WithKyuubiServer with HiveJDBCTe
       assert(connection.getEngineId.startsWith("local-"))
       assert(connection.getEngineName.startsWith("kyuubi"))
       assert(connection.getEngineUrl.nonEmpty)
+      assert(connection.getEngineRefId.nonEmpty)
       val stmt = connection.createStatement()
       try {
         stmt.execute("select engine_name()")
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/BackendServiceMetricSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/BackendServiceMetricSuite.scala
index 53a53ef1d..a58d1842c 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/BackendServiceMetricSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/BackendServiceMetricSuite.scala
@@ -78,7 +78,7 @@ class BackendServiceMetricSuite extends WithKyuubiServer with HiveJDBCTestHelper
 
       val meters2 =
         objMapper.readTree(Paths.get(reportPath.toString, "report.json").toFile).get("meters")
-      assert(meters2.get(MetricsConstants.BS_FETCH_RESULT_ROWS_RATE).get("count").asInt() == 7)
+      assert(meters2.get(MetricsConstants.BS_FETCH_RESULT_ROWS_RATE).get("count").asInt() == 8)
       assert(meters2.get(MetricsConstants.BS_FETCH_LOG_ROWS_RATE).get("count").asInt() >= logRows1)
 
       statement.executeQuery("DROP TABLE stu_test")