shivadarshan-devadiga commented on code in PR #60750:
URL: https://github.com/apache/spark/pull/60750#discussion_r4642168058


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ApplyCharTypePaddingHelper.scala:
##########
@@ -48,6 +49,22 @@ object ApplyCharTypePaddingHelper {
     }
   }
 
+  /**
+   * A column, or a field of a struct column reached through 
[[GetStructField]], with the raw type
+   * of that column or field. The raw type is the one recorded in the column's 
metadata, so a CHAR
+   * or VARCHAR field keeps its length although its data type is a string.
+   */
+  object RawTypedRef {
+    def unapply(e: Expression): Option[DataType] = e match {
+      case AttrOrOuterRef(attr) => CharVarcharUtils.getRawType(attr.metadata)
+      case GetStructField(child, ordinal, _) =>
+        unapply(child).collect {
+          case struct: StructType if ordinal < struct.length => 
struct(ordinal).dataType

Review Comment:
   Thanks, fixed. `RawTypedRef` now looks the field up by name in the raw 
struct, and only uses its raw type if it still matches the field's current 
type, ignoring nullability. Your example is covered in `SPARK-61970: a 
reordered struct field keeps its own raw type`: `s.v = 'a'` is true again, and 
the moved CHAR field `s.c = 'x'` is still padded.



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