cloud-fan commented on a change in pull request #26933: [SPARK-30292][SQL]Throw
Exception when invalid string is cast to numeric type in ANSI mode
URL: https://github.com/apache/spark/pull/26933#discussion_r364134987
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -1358,13 +1401,20 @@ abstract class CastBase extends UnaryExpression with
TimeZoneAwareExpression wit
case StringType =>
val wrapper = ctx.freshVariable("intWrapper",
classOf[UTF8String.IntWrapper])
(c, evPrim, evNull) =>
+ val casting = if (ansiEnabled) {
+ s"$evPrim = $c.toByteExact();"
+ } else {
+ s"""
+ if ($c.toByte($wrapper)) {
+ $evPrim = (byte) $wrapper.value;
+ } else {
+ $evNull = true;
+ }
+ """
+ }
code"""
UTF8String.IntWrapper $wrapper = new UTF8String.IntWrapper();
Review comment:
ah we don't need to create int wrapper at all for ansi mode
```
case StringType if ansi => (c, evPrim, evNull) => s"$evPrim =
$c.toByteExact();"
case StringType => // the original code
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]