dongjoon-hyun commented on a change in pull request #30472:
URL: https://github.com/apache/spark/pull/30472#discussion_r535756787
##########
File path:
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/submit/KubernetesClientUtils.scala
##########
@@ -51,6 +54,29 @@ private[spark] object KubernetesClientUtils extends Logging {
propertiesWriter.toString
}
+ object StringLengthOrdering extends Ordering[(String, String)] {
+ override def compare(x: (String, String), y: (String, String)): Int = {
+ // compare based on file length and break the tie with string comparison
of keys.
+ (x._1.length + x._2.length).compare(y._1.length + y._2.length) * 10 +
+ x._1.compareTo(y._1)
+ }
+ }
+
+ def truncateToSize(seq: Seq[(String, String)], maxSize: Long): Map[String,
String] = {
+ // First order the entries in order of their size.
+ // Skip entries if the resulting Map size exceeds maxSize.
+ val ordering: Ordering[(String, String)] = StringLengthOrdering
+ val sortedSet = SortedSet[(String, String)](seq : _*)(ordering)
+ var i: Int = 0
+ val map = mutable.HashMap[String, String]()
+ for (item <- sortedSet) {
+ i += item._1.length + item._2.length
+ if ( i < maxSize) {
Review comment:
```scala
- if ( i < maxSize) {
+ if (i < maxSize) {
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]