cloud-fan commented on a change in pull request #27066:
URL: https://github.com/apache/spark/pull/27066#discussion_r448396274



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/ComplexTypes.scala
##########
@@ -39,7 +41,15 @@ object SimplifyExtractValueOps extends Rule[LogicalPlan] {
       // Remove redundant field extraction.
       case GetStructField(createNamedStruct: CreateNamedStruct, ordinal, _) =>
         createNamedStruct.valExprs(ordinal)
-
+      case GetStructField(w@WithFields(struct, names, valExprs), ordinal, 
maybeGetFieldName) =>
+        val getFieldName = 
maybeGetFieldName.getOrElse(w.dataType(ordinal).name)
+        val resolver = SQLConf.get.resolver
+        val matches = names.zip(valExprs).filter { case (name, _) => 
resolver(name, getFieldName) }
+        if (matches.nonEmpty) {
+          matches.last._2

Review comment:
       This is for case like `$"struct_col".withField("b", 
lit(100)).withField("b", lit(200))` while the last one takes effect. Can we add 
some comments to mention it?




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

Reply via email to