cloud-fan commented on a change in pull request #29731:
URL: https://github.com/apache/spark/pull/29731#discussion_r488710003
##########
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)
Review comment:
This is a performance-critical code path. Can we avoid repeatedly
creating Tuple2 objects? We can add a private method to calculate precision.
----------------------------------------------------------------
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]