attilapiros commented on code in PR #53458:
URL: https://github.com/apache/spark/pull/53458#discussion_r2756216614
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -1380,7 +1414,41 @@ case class Cast(
val fromArg = ctx.addReferenceObj("from", from)
(c, evPrim, evNull) => code"$evPrim = $cls.castToVariant($c, $fromArg);"
case s: StringType =>
- (c, evPrim, _) => castToStringCode(from, ctx, s.constraint).apply(c,
evPrim)
+ // BinaryType to StringType cast with UTF-8 validation
+ from match {
+ case BinaryType =>
+ val tmp = ctx.freshVariable("tmp", classOf[UTF8String])
+
+ if (!validateUtf8) {
+ // Old behavior: no validation
+ (c, evPrim, evNull) =>
+ code"$evPrim = UTF8String.fromBytes($c);"
Review Comment:
Are you sure this is the old behavior?
As the old `castToStringCode` call was maintaining length constraints:
https://github.com/apache/spark/blob/c94ce2c23f27b6e9e3256681947e91e82698c8bc/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ToStringBase.scala#L191-L199
and
https://github.com/apache/spark/blob/c94ce2c23f27b6e9e3256681947e91e82698c8bc/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ToStringBase.scala#L203
--
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]