srielau commented on code in PR #58080:
URL: https://github.com/apache/spark/pull/58080#discussion_r3817412038


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CollationTypeCoercion.scala:
##########
@@ -115,7 +122,8 @@ object CollationTypeCoercion extends SQLConfHelper {
 
         expr match {
           case lit: Literal => lit.copy(dataType = newDataType)

Review Comment:
   Fixed. `changeType` still `copy`s when only collation changes. When the 
string constraint changes (CHAR(2) to CHAR(4), including nested 
array/map/struct), it wraps in Cast so padding / length checks re-apply. 
Covered by `SPARK-58794: typed CHAR Literal is re-padded when LCT widens the 
length` (`Literal.create("a", CharType(2, UTF8_LCASE))` coalesced with CHAR(4) 
yields `"a   "`).



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -184,13 +184,39 @@ object Project {
         if (other == target) {
           col
         } else if (Cast.canANSIStoreAssign(other, target)) {
-          Cast(col, target, Option(conf.sessionLocalTimeZone), ansiEnabled = 
true)
+          storeAssignCast(col, other, target, conf)
         } else {
           throw 
QueryCompilationErrors.invalidColumnOrFieldDataTypeError(columnPath, other, 
target)
         }
     }
   }
 
+  // Store assignment must not use character-to-character CAST truncation (ISO 
6.13).
+  // Cast to unconstrained STRING first, then apply the write-side length 
check.
+  // Avoid replaceCharVarcharWithString: first-class types keep CHAR/VARCHAR.
+  private def storeAssignCast(

Review Comment:
   Done. The three-line contract is now Scaladoc on `storeAssignCast`, 
including the STRING-then-write-check plan shape for CHAR/VARCHAR targets.



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