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/incubator-kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new fe8933c  [KYUUBI #1277] Add KDF engine_id
fe8933c is described below

commit fe8933c8ec0ac2f88c295f2a90a2b1545aad0e92
Author: fwang12 <[email protected]>
AuthorDate: Sat Oct 23 21:05:16 2021 +0800

    [KYUUBI #1277] Add KDF engine_id
    
    <!--
    Thanks for sending a pull request!
    
    Here are some tips for you:
      1. If this is your first time, please read our contributor guidelines: 
https://kyuubi.readthedocs.io/en/latest/community/contributions.html
      2. If the PR is related to an issue in 
https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your 
PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
      3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
'[WIP][KYUUBI #XXXX] Your PR title ...'.
    -->
    
    ### _Why are the changes needed?_
    <!--
    Please clarify why the changes are needed. For instance,
      1. If you add a feature, you can talk about the use case of it.
      2. If you fix a bug, you can clarify why it is a bug.
    -->
    It is useful for client side.
    
    ### _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/latest/develop_tools/testing.html#running-tests)
 locally before make a pull request
    
    Closes #1277 from turboFei/engine_id.
    
    Closes #1277
    
    95526f09 [fwang12] remove redundant test
    382c96dc [fwang12] test all the jdbc tests with yarn mode
    01b2ea13 [fwang12] add udf engine_id
    
    Authored-by: fwang12 <[email protected]>
    Signed-off-by: fwang12 <[email protected]>
---
 docs/sql/functions.md                                          |  1 +
 .../scala/org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala |  9 +++++++++
 .../src/test/scala/org/apache/kyuubi/operation/JDBCTests.scala |  8 ++++++++
 .../kyuubi/operation/KyuubiOperationYarnClusterSuite.scala     | 10 +---------
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/docs/sql/functions.md b/docs/sql/functions.md
index ba9df14..d2ab176 100644
--- a/docs/sql/functions.md
+++ b/docs/sql/functions.md
@@ -31,5 +31,6 @@ Name | Description | Return Type | Since
 --- | --- | --- | ---
 kyuubi_version | Return the version of Kyuubi Server | string | 1.3.0
 engine_name | Return the spark application name for the associated query 
engine | string | 1.3.0
+engine_id | Return the spark application id for the associated query engine | 
string | 1.4.0
 system_user | Return the system user name for the associated query engine | 
string | 1.3.0
 
diff --git 
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala
 
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala
index 11900f7..af58c4c 100644
--- 
a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala
+++ 
b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala
@@ -32,6 +32,7 @@ object KDFRegistry {
   val registeredFunctions = new ArrayBuffer[KyuubiDefinedFunction]()
 
   val appName = SparkEnv.get.conf.get("spark.app.name")
+  val appId = SparkEnv.get.conf.get("spark.app.id")
 
   val kyuubi_version: KyuubiDefinedFunction = create(
     "kyuubi_version",
@@ -48,6 +49,14 @@ object KDFRegistry {
     "1.3.0"
   )
 
+  val engine_id: KyuubiDefinedFunction = create(
+    "engine_id",
+    udf(() => appId).asNonNullable(),
+    "Return the spark application id for the associated query engine",
+    "string",
+    "1.4.0"
+  )
+
   val system_user: KyuubiDefinedFunction = create(
     "system_user",
     udf(() => System.getProperty("user.name")).asNonNullable(),
diff --git 
a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/JDBCTests.scala 
b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/JDBCTests.scala
index e2c9f7e..1b0e2d8 100644
--- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/JDBCTests.scala
+++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/JDBCTests.scala
@@ -374,6 +374,14 @@ trait JDBCTests extends BasicJDBCTests {
     }
   }
 
+  test("kyuubi defined function - engine_id") {
+    withJdbcStatement() { statement =>
+      val rs = statement.executeQuery("SELECT engine_id()")
+      assert(rs.next())
+      assert(StringUtils.isNotBlank(rs.getString(1)))
+    }
+  }
+
   test("kyuubi defined function - system_user") {
     withJdbcStatement() { statement =>
       val rs = statement.executeQuery("SELECT system_user()")
diff --git 
a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationYarnClusterSuite.scala
 
b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationYarnClusterSuite.scala
index 734406e..f1eb930 100644
--- 
a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationYarnClusterSuite.scala
+++ 
b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationYarnClusterSuite.scala
@@ -21,7 +21,7 @@ import org.apache.kyuubi.WithKyuubiServerOnYarn
 import org.apache.kyuubi.config.KyuubiConf
 import org.apache.kyuubi.config.KyuubiConf.ENGINE_INIT_TIMEOUT
 
-class KyuubiOperationYarnClusterSuite extends WithKyuubiServerOnYarn with 
JDBCTestUtils {
+class KyuubiOperationYarnClusterSuite extends WithKyuubiServerOnYarn with 
JDBCTests {
 
   override protected def jdbcUrl: String = getJdbcUrl
 
@@ -42,12 +42,4 @@ class KyuubiOperationYarnClusterSuite extends 
WithKyuubiServerOnYarn with JDBCTe
       assert(resultSet.getString("id").startsWith("application_"))
     }
   }
-
-  test("KYUUBI #1263: Kyuubi auxiliary UDF failed on Spark Yarn mode") {
-    withJdbcStatement() { statement =>
-      val resultSet = statement.executeQuery("""SELECT kyuubi_version() as 
id""")
-      assert(resultSet.next())
-      assert(resultSet.getString("id") === org.apache.kyuubi.KYUUBI_VERSION)
-    }
-  }
 }

Reply via email to