From cd308f38adf44af72a254c4706abd0dfbef1a887 Mon Sep 17 00:00:00 2001 From: Min Zhao Date: Mon, 19 Jul 2021 18:16:38 +0800 Subject: [PATCH] [KYUUBI #758] [KYUUBI 661] Add UDF system_user ### _Why are the changes needed?_ add udf system_user. ### _How was this patch tested?_ - [ ] 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/tools/testing.html#running-tests) locally before make a pull request Closes #758 from zhaomin1423/661_add-system_user. Closes #758 70eba56a [Min Zhao] update system user name f5edc621 [Min Zhao] [KYUUBI 661] Add UDF system_user Authored-by: Min Zhao Signed-off-by: Kent Yao --- docs/sql/functions.md | 1 + .../org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala | 7 +++++++ .../scala/org/apache/kyuubi/operation/JDBCTests.scala | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/docs/sql/functions.md b/docs/sql/functions.md index 90a09e503..0415e7b83 100644 --- a/docs/sql/functions.md +++ b/docs/sql/functions.md @@ -13,4 +13,5 @@ Kyuubi provides several auxiliary SQL functions as supplement to Spark's [Built- Name | Description | Return Type | Since --- | --- | --- | --- kyuubi_version | Return the version of Kyuubi Server | string | 1.3.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 98c4077fd..14c837af8 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 @@ -36,6 +36,13 @@ object KDFRegistry { "string", "1.3.0") + val system_user: KyuubiDefinedFunction = create( + "system_user", + udf(() => System.getProperty("user.name")).asNonNullable(), + "Return the system user name for the associated query engine", + "string", + "1.3.0") + def create( name: String, udf: UserDefinedFunction, 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 660a1f046..fa0ed60bb 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 @@ -359,4 +359,12 @@ trait JDBCTests extends BasicJDBCTests { assert(rs.getString(1) == KYUUBI_VERSION) } } + + test("kyuubi defined function - system_user") { + withJdbcStatement() { statement => + val rs = statement.executeQuery("SELECT system_user()") + assert(rs.next()) + assert(rs.getString(1) == System.getProperty("user.name")) + } + } }