cloud-fan commented on a change in pull request #29731:
URL: https://github.com/apache/spark/pull/29731#discussion_r488707989
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala
##########
@@ -589,6 +587,50 @@ object Decimal {
}
}
+ private def stringToJavaBigDecimal(str: UTF8String): (JavaBigDecimal, Int) =
{
+ // According the benchmark test, `s.toString.trim` is much faster than
`s.trim.toString`.
+ // Please refer to https://github.com/apache/spark/pull/26640
+ val bigDecimal = new JavaBigDecimal(str.toString.trim)
+ val precision = if (bigDecimal.scale < 0) {
+ bigDecimal.precision - bigDecimal.scale
+ } else {
+ bigDecimal.precision
+ }
+ (bigDecimal, precision)
+ }
+
+ def fromString(str: UTF8String): Decimal = {
+ try {
+ val (bigDecimal, precision) = stringToJavaBigDecimal(str)
+ // We fast fail because constructing a very large JavaBigDecimal to
Decimal very slow.
Review comment:
nit: `very slow` => `is very slow`
----------------------------------------------------------------
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]