You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/09/14 06:51:59 UTC
[GitHub] [spark] sunchao commented on a change in pull request #33981: [SPARK-36733][SQL] Fix a perf issue in SchemaPruning when a struct has many fields
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org