sunchao commented on a change in pull request #33981:
URL: https://github.com/apache/spark/pull/33981#discussion_r707963448



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SchemaPruning.scala
##########
@@ -65,16 +67,19 @@ object SchemaPruning extends SQLConfHelper {
           sortLeftFieldsByRight(leftValueType, rightValueType),
           containsNull)
       case (leftStruct: StructType, rightStruct: StructType) =>
-        val resolver = conf.resolver
-        val filteredRightFieldNames = rightStruct.fieldNames
-          .filter(name => leftStruct.fieldNames.exists(resolver(_, name)))
-        val sortedLeftFields = filteredRightFieldNames.map { fieldName =>
-          val resolvedLeftStruct = leftStruct.find(p => resolver(p.name, 
fieldName)).get
-          val leftFieldType = resolvedLeftStruct.dataType
-          val rightFieldType = rightStruct(fieldName).dataType
-          val sortedLeftFieldType = sortLeftFieldsByRight(leftFieldType, 
rightFieldType)
-          StructField(fieldName, sortedLeftFieldType, nullable = 
resolvedLeftStruct.nullable,
-            metadata = resolvedLeftStruct.metadata)
+        val leftStructTreeMap =
+          TreeMap(leftStruct.map(_.name).zip(leftStruct): 
_*)(conf.fieldNameOrdering)

Review comment:
       I wonder if we can use a `HashMap` for this:
   
   ```scala
     private def formatFieldName(name: String): String =
       if (conf.caseSensitiveAnalysis) name else name.toLowerCase(Locale.ROOT)
   
     ...
   
     val leftStructTreeMap =
       HashMap(leftStruct.map(f => formatFieldName(f.name)).zip(leftStruct): _*)
   ```




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