wombatu-kun commented on code in PR #20458:
URL: https://github.com/apache/hudi/pull/20458#discussion_r4408081760


##########
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:
   A binary column cast directly to a collated string (`CAST(bin AS STRING 
COLLATE UTF8_LCASE) = 'a'`) still falls through to `case _ => true`, and column 
stats V2 indexes binary columns, so its byte-ordered bounds get compared in 
UTF8_LCASE just like in the repro. Should `(BinaryType, toStr: StringType)` 
also be rejected unless `toStr == StringType`?



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