我正在使用 Apache Spark 的 SQL 来处理结构大数据。我遇到过 Spark SQL 数据类型的使用,特别是 DecimalType,它比 SparkSQL 中的任何其他数据类型都支持最大数量的存储,但高达 38 的精度,即使根据文档:http://spark.apache.org/docs/latest/sql-programming-guide.html#data-types您可以在其中找到:它内部使用 Scala 语言的 BigDecimal,允许精度约为。 2^32。为什么会这样呢?
我需要通过sparkSQL实现scala的BigDecimal提供的相同功能。我可以知道如何实现此问题的解决方案或我可以尝试的任何其他方法吗?
最佳答案
spark 在底层使用了 Java 的 BigDecimal。
https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html
A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. The value of the number represented by the BigDecimal is therefore (unscaledValue × 10-scale).
关于java - 为什么SparkSQL中org.apache.spark.sql.types.DecimalType的最大精度值为38?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40585319/