Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for allow-precision-loss in decimal operations (facebooki…
…ncubator#10383) Summary: Each of the decimal operation functions is registered as two functions such as `add_deny_precision_loss` and `add`. When allowing precision loss, establishing the result type of an arithmetic operation happens according to Hive behavior and SQL ANSI 2011 specification, i.e. rounding the decimal part of the result if an exact representation is not possible. Otherwise, NULL is returned in those cases, as previously. When not allowing precision loss, not rounding the decimal part. For example, | decimal(38, 7) + decimal(10, 0) result type | 1.1232154 + 1| decimal(38, 18) * decimal(38, 18)| 0.1234567891011 * 1234.1 -- | -- | -- | -- | -- allow precision loss | decimal(38, 6) | 2.123215 | decimal(38, 6) | 152.358023 deny precision loss | decimal(38, 7) | 2.1232154 | decimal(38, 36) | NULL ``` spark-sql (default)> set spark.sql.decimalOperations.allowPrecisionLoss=true; spark-sql (default)> select cast(0.1234567891011 as decimal(38, 18)) * cast(1234.1 as decimal(38, 18)); 152.358023 spark-sql (default)> set spark.sql.decimalOperations.allowPrecisionLoss=false; spark-sql (default)> select cast(0.1234567891011 as decimal(38, 18)) * cast(1234.1 as decimal(38, 18)); NULL ``` Spark implementation: https://github.com/apache/spark/blob/branch-3.5/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala#L814 Pull Request resolved: facebookincubator#10383 Reviewed By: pedroerp Differential Revision: D65612198 Pulled By: kevinwilfong fbshipit-source-id: 4910aaeb0e375dbe8817c5f3fb41185c67c6dd5b
- Loading branch information