[KYUUBI #3848] [Improvement] Sort config map returned inKyuubiConf.getAll

### _Why are the changes needed?_

to close #3848 .

Sort the config map returned in KyuubiConf.getAll to improve readability of engine launching configs in output.

### _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

- [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #3849 from bowenliang123/sort-configs.

Closes #3848

75e60c89 [liangbowen] sort the returned map of getAll in KyuubiConf  (+4 squashed commits) Squashed commits: [f102b423] update method comment [465d7b25] use TreeMap for sorting [1a66e05b] add getAllSorted [2b3dbf91] sort the returned map of getAll in KyuubiConf

Authored-by: liangbowen <liangbowen@gf.com.cn>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
liangbowen 2022-11-25 18:44:52 +08:00 committed by Cheng Pan
parent 00d2d2eb67
commit b5bfd97e01
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
2 changed files with 23 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.regex.Pattern
import scala.collection.JavaConverters._
import scala.collection.immutable.TreeMap
import scala.util.matching.Regex
import org.apache.kyuubi.{Logging, Utils}
@ -112,9 +113,12 @@ case class KyuubiConf(loadSysDefault: Boolean = true) extends Logging {
unset(entry.key)
}
/** Get all parameters as map */
/**
* Get all parameters as map
* sorted by key in ascending order
*/
def getAll: Map[String, String] = {
settings.entrySet().asScala.map(x => (x.getKey, x.getValue)).toMap[String, String]
TreeMap(settings.asScala.toSeq: _*)
}
/** Get all envs as map */

View File

@ -183,4 +183,21 @@ class KyuubiConfSuite extends KyuubiFunSuite {
assert(kyuubiConf.getBatchConf("spark") == Map("spark.yarn.tags" -> "kyuubi"))
assert(kyuubiConf.getBatchConf("flink") == Map("yarn.tags" -> "kyuubi"))
}
test("KYUUBI #3848 - Sort config map returned in KyuubiConf.getAll") {
val kyuubiConf = KyuubiConf(false)
kyuubiConf.set("kyuubi.xyz", "123")
kyuubiConf.set("kyuubi.efg", "")
kyuubiConf.set("kyuubi.abc", "789")
var kSeq = Seq[String]()
kyuubiConf.getAll.foreach { case (k, v) =>
kSeq = kSeq :+ k
}
assertResult(kSeq.size)(3)
assertResult(kSeq.head)("kyuubi.abc")
assertResult(kSeq(1))("kyuubi.efg")
assertResult(kSeq(2))("kyuubi.xyz")
}
}