Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/22037#discussion_r209067476
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala ---
@@ -479,6 +481,26 @@ object Decimal {
dec
}
+ // Max precision of a decimal value stored in `numBytes` bytes
+ def maxPrecisionForBytes(numBytes: Int): Int = {
+ Math.round( // convert double to long
+ Math.floor(Math.log10( // number of base-10 digits
+ Math.pow(2, 8 * numBytes - 1) - 1))) // max value stored in
numBytes
+ .asInstanceOf[Int]
+ }
+
+ // Returns the minimum number of bytes needed to store a decimal with a
given `precision`.
+ lazy val minBytesForPrecision =
Array.tabulate[Int](39)(computeMinBytesForPrecision)
+
+
--- End diff --
nit: seems an extra blank line here.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]