aokolnychyi commented on code in PR #40206:
URL: https://github.com/apache/spark/pull/40206#discussion_r1119509603


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala:
##########
@@ -139,33 +139,46 @@ object TableOutputResolver {
   private def resolveStructType(
       input: NamedExpression,
       inputType: StructType,
+      expectedCol: Attribute,
       expectedType: StructType,
-      expectedName: String,
       conf: SQLConf,
       addError: String => Unit,
       colPath: Seq[String]): Option[NamedExpression] = {
     val fields = inputType.zipWithIndex.map { case (f, i) =>
       Alias(GetStructField(input, i, Some(f.name)), f.name)()
     }
-    val reordered = reorderColumnsByName(fields, expectedType.toAttributes, 
conf, addError, colPath)
-    if (reordered.length == expectedType.length) {
+    val fieldAttrs = createStructFieldAttrs(expectedCol, expectedType)
+    val reordered = reorderColumnsByName(fields, fieldAttrs, conf, addError, 
colPath)
+    if (reordered.length == fieldAttrs.length) {
       val struct = CreateStruct(reordered)
       val res = if (input.nullable) {
         If(IsNull(input), Literal(null, struct.dataType), struct)
       } else {
         struct
       }
-      Some(Alias(res, expectedName)())
+      Some(Alias(res, expectedCol.name)())
     } else {
       None
     }
   }
 
+  private def createStructFieldAttrs(attr: Attribute, attrType: StructType): 
Seq[Attribute] = {

Review Comment:
   I can't say I am entirely happy with this solution so if there are any 
ideas, let me know.



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