HyukjinKwon commented on code in PR #54117:
URL: https://github.com/apache/spark/pull/54117#discussion_r2766529115


##########
sql/api/src/main/scala/org/apache/spark/sql/types/StructType.scala:
##########
@@ -122,6 +122,10 @@ case class StructType(fields: Array[StructField]) extends 
DataType with Seq[Stru
   private lazy val nameToIndex: Map[String, Int] = 
SparkCollectionUtils.toMapWithIndex(fieldNames)
   private lazy val nameToIndexCaseInsensitive: CaseInsensitiveMap[Int] =
     CaseInsensitiveMap[Int](nameToIndex.toMap)
+  lazy val nameToDataType: collection.immutable.Map[String, DataType] =
+    fields.map(f => f.name -> f.dataType).toMap

Review Comment:
   StructType itself is `Seq[StructField]` so you can just do `s.map(f => 
f.name -> f.dataType)` which I don't think it's worth as an API.



##########
sql/api/src/main/scala/org/apache/spark/sql/types/StructType.scala:
##########
@@ -122,6 +122,10 @@ case class StructType(fields: Array[StructField]) extends 
DataType with Seq[Stru
   private lazy val nameToIndex: Map[String, Int] = 
SparkCollectionUtils.toMapWithIndex(fieldNames)
   private lazy val nameToIndexCaseInsensitive: CaseInsensitiveMap[Int] =
     CaseInsensitiveMap[Int](nameToIndex.toMap)
+  lazy val nameToDataType: collection.immutable.Map[String, DataType] =
+    fields.map(f => f.name -> f.dataType).toMap

Review Comment:
   StructType itself is `Seq[StructField]` so you can just do `s.map(f => 
f.name -> f.dataType)` which I don't think it's worth as an API.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to