voonhous commented on code in PR #20458:
URL: https://github.com/apache/hudi/pull/20458#discussion_r4420375191


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/HoodieSparkTypeUtils.scala:
##########
@@ -36,9 +36,15 @@ object HoodieSparkTypeUtils {
   def isCastPreservingOrdering(from: DataType, to: DataType): Boolean =
     (from, to) match {
       // NOTE: In the casting rules defined by Spark, only casting from String 
to Numeric
-      // (and vice versa) are the only casts that might break the ordering of 
the elements after casting
-      case (StringType, _: NumericType) => false
-      case (_: NumericType, StringType) => false
+      // (and vice versa) are the only casts that might break the ordering of 
the elements after casting.
+      // These match by type, so that collated strings on Spark 4 are rejected 
as well
+      case (_: StringType, _: NumericType) => false
+      case (_: NumericType, _: StringType) => false
+      // NOTE: On Spark 4 StringType carries a collation, and casting to a 
different collation changes
+      //       the sort order (for ex, "B" < "a" in UTF8_BINARY but "a" < "B" 
in UTF8_LCASE). Equality
+      //       also compares the char/varchar length constraint, so those 
casts are conservatively
+      //       rejected too. On Spark 3 StringType is a singleton, making this 
arm trivially true
+      case (fromStr: StringType, toStr: StringType) => fromStr == toStr

Review Comment:
   Yes, fixed in 79c5c0d7e2fb, and by target rather than by source: every type 
casts to a string, so any cast into a non-default `StringType` is now rejected 
(binary, date, timestamp, ...), not only `string -> string`. Added binary and 
date cases to the collation unit test.



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

Reply via email to