Skip to content

Commit cd308f3

Browse files
zhaomin1423yaooqinn
authored andcommitted
[KYUUBI apache#758] [KYUUBI 661] Add UDF system_user
<!-- 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/NetEase/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. --> 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 apache#758 from zhaomin1423/661_add-system_user. Closes apache#758 70eba56 [Min Zhao] update system user name f5edc62 [Min Zhao] [KYUUBI 661] Add UDF system_user Authored-by: Min Zhao <zhaomin1423@163.com> Signed-off-by: Kent Yao <yao@apache.org>
1 parent e7e77f9 commit cd308f3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

docs/sql/functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ Kyuubi provides several auxiliary SQL functions as supplement to Spark's [Built-
1313
Name | Description | Return Type | Since
1414
--- | --- | --- | ---
1515
kyuubi_version | Return the version of Kyuubi Server | string | 1.3.0
16+
system_user | Return the system user name for the associated query engine | string | 1.3.0
1617

externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ object KDFRegistry {
3636
"string",
3737
"1.3.0")
3838

39+
val system_user: KyuubiDefinedFunction = create(
40+
"system_user",
41+
udf(() => System.getProperty("user.name")).asNonNullable(),
42+
"Return the system user name for the associated query engine",
43+
"string",
44+
"1.3.0")
45+
3946
def create(
4047
name: String,
4148
udf: UserDefinedFunction,

kyuubi-common/src/test/scala/org/apache/kyuubi/operation/JDBCTests.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,12 @@ trait JDBCTests extends BasicJDBCTests {
359359
assert(rs.getString(1) == KYUUBI_VERSION)
360360
}
361361
}
362+
363+
test("kyuubi defined function - system_user") {
364+
withJdbcStatement() { statement =>
365+
val rs = statement.executeQuery("SELECT system_user()")
366+
assert(rs.next())
367+
assert(rs.getString(1) == System.getProperty("user.name"))
368+
}
369+
}
362370
}

0 commit comments

Comments
 (0)