Skip to content

Commit 561c21d

Browse files
yuexingyhuang-db
authored andcommitted
[SPARK-52299][CORE] replace deprecated JsonNode.fields
### What changes were proposed in this pull request? JsonNode.fields is deprecated, and is supposed to be replaced as JsonNode.properties. ### Why are the changes needed? Without the fix, there're warning during compile: [warn] /path/to/spark/core/src/main/scala/org/apache/spark/util/JsonProtocol.scala:1026:10: method fields in class JsonNode is deprecated [warn] Applicable -Wconf / nowarn filters for this warning: msg=<part of the message>, cat=deprecation, site=org.apache.spark.util.JsonProtocol.taskResourceRequestMapFromJson, origin=com.fasterxml.jackson.databind.JsonNode.fields [warn] json.fields().asScala.collect { case field => [warn] ^ ### Does this PR introduce _any_ user-facing change? No, it only fixes compilation warning. ### How was this patch tested? after the fix, no such warning during compilation. all ut passes. ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#51011 from yuexing/SPARK-52299. Authored-by: xingyue <xingyue@baidu.com> Signed-off-by: yangjie01 <yangjie01@baidu.com>
1 parent 2c945f2 commit 561c21d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

core/src/main/scala/org/apache/spark/util/JsonProtocol.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,14 @@ private[spark] class JsonProtocol(sparkConf: SparkConf) extends JsonUtils {
10231023
}
10241024

10251025
def taskResourceRequestMapFromJson(json: JsonNode): Map[String, TaskResourceRequest] = {
1026-
json.fields().asScala.collect { case field =>
1026+
json.properties().asScala.collect { case field =>
10271027
val req = taskResourceRequestFromJson(field.getValue)
10281028
(field.getKey, req)
10291029
}.toMap
10301030
}
10311031

10321032
def executorResourceRequestMapFromJson(json: JsonNode): Map[String, ExecutorResourceRequest] = {
1033-
json.fields().asScala.collect { case field =>
1033+
json.properties().asScala.collect { case field =>
10341034
val req = executorResourceRequestFromJson(field.getValue)
10351035
(field.getKey, req)
10361036
}.toMap
@@ -1543,7 +1543,7 @@ private[spark] class JsonProtocol(sparkConf: SparkConf) extends JsonUtils {
15431543

15441544
def resourcesMapFromJson(json: JsonNode): Map[String, ResourceInformation] = {
15451545
assert(json.isObject, s"expected object, got ${json.getNodeType}")
1546-
json.fields.asScala.map { field =>
1546+
json.properties.asScala.map { field =>
15471547
val resourceInfo = ResourceInformation.parseJson(field.getValue.toString)
15481548
(field.getKey, resourceInfo)
15491549
}.toMap
@@ -1555,7 +1555,7 @@ private[spark] class JsonProtocol(sparkConf: SparkConf) extends JsonUtils {
15551555

15561556
def mapFromJson(json: JsonNode): Map[String, String] = {
15571557
assert(json.isObject, s"expected object, got ${json.getNodeType}")
1558-
json.fields.asScala.map { field =>
1558+
json.properties.asScala.map { field =>
15591559
(field.getKey, field.getValue.extractString)
15601560
}.toMap
15611561
}

core/src/test/scala/org/apache/spark/util/JsonProtocolSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ private[spark] object jsonProtocolSuite extends Assertions {
13561356
case ((key1, values1: scala.collection.Seq[(String, String)]),
13571357
(key2, values2: scala.collection.Seq[(String, String)])) =>
13581358
assert(key1 === key2)
1359-
values1.zip(values2).foreach { case (v1, v2) => assert(v1 === v2) }
1359+
assert(values1.toMap == values2.toMap)
13601360
}
13611361
}
13621362

0 commit comments

Comments
 (0)