wangyum commented on a change in pull request #29731:
URL: https://github.com/apache/spark/pull/29731#discussion_r488676798
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -670,18 +705,7 @@ abstract class CastBase extends UnaryExpression with
TimeZoneAwareExpression wit
private[this] def castToDecimal(from: DataType, target: DecimalType): Any =>
Any = from match {
case StringType =>
- buildCast[UTF8String](_, s => try {
- // According the benchmark test, `s.toString.trim` is much faster
than `s.trim.toString`.
- // Please refer to https://github.com/apache/spark/pull/26640
- changePrecision(Decimal(new JavaBigDecimal(s.toString.trim)), target)
- } catch {
- case _: NumberFormatException =>
- if (ansiEnabled) {
- throw new NumberFormatException(s"invalid input syntax for type
numeric: $s")
- } else {
- null
- }
- })
+ buildCast[UTF8String](_, s => stringToDecimal(s, target))
Review comment:

----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]