Skip to content

Commit 8cef5c8

Browse files
hddongulysses-you
authored andcommitted
[KYUUBI apache#839]Fix load user specific defaults from properties file
<!-- 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. --> loadFromMap ignored user specific defaults that start with '___'. ### _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/tools/testing.html#running-tests) locally before make a pull request Closes apache#840 from hddong/kyuubi-839. Closes apache#839 ba3683e [hongdongdong] fix comments a775384 [hongdongdong] fix test 07f8266 [hongdongdong] fix test b2a4c3c [hongdongdong] [KYUUBI#839]Fix load user specific defaults from properties file Authored-by: hongdongdong <hongdongdong@cmss.chinamobile.com> Signed-off-by: ulysses-you <ulyssesyou18@gmail.com>
1 parent 7ee92ce commit 8cef5c8

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ case class KyuubiConf(loadSysDefault: Boolean = true) extends Logging {
3939
}
4040

4141
private def loadFromMap(props: Map[String, String] = Utils.getSystemProperties): KyuubiConf = {
42-
for ((key, value) <- props if key.startsWith("kyuubi.") || key.startsWith("spark.")) {
42+
for ((key, value) <- props if key.startsWith("kyuubi.") || key.startsWith("spark.") ||
43+
// for user specific defaults
44+
key.startsWith("___")) {
4345
set(key, value)
4446
}
4547
this

kyuubi-common/src/test/resources/kyuubi-defaults.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@
1818
kyuubi.yes yes
1919
spark.kyuubi.yes no
2020
# kyuubi.no no
21+
22+
spark.user.test a
23+
___userb___.spark.user.test b
24+
___userc___.spark.user.test c

kyuubi-common/src/test/scala/org/apache/kyuubi/config/KyuubiConfSuite.scala

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,10 @@ class KyuubiConfSuite extends KyuubiFunSuite {
9797

9898

9999
test("get user specific defaults") {
100-
val conf = KyuubiConf(false)
101-
.set("spark.user.test", "a")
102-
.set("___userb___.spark.user.test", "b")
103-
.set("___userc___.spark.user.test", "c")
104-
105-
val all1 = conf.getUserDefaults("kyuubi").getAll
106-
assert(all1.size === 1)
107-
assert(all1("spark.user.test") === "a")
108-
val all2 = conf.getUserDefaults("userb").getAll
109-
assert(all2.size === 1)
110-
assert(all2("spark.user.test") === "b")
100+
val conf = KyuubiConf().loadFileDefaults()
101+
102+
assert(conf.getUserDefaults("kyuubi").getOption("spark.user.test").get === "a")
103+
assert(conf.getUserDefaults("userb").getOption("spark.user.test").get === "b")
111104
assert(conf.getUserDefaults("userc").getOption("spark.user.test").get === "c")
112105
}
113106

0 commit comments

Comments
 (0)