GitHub user stanzhai opened a pull request: https://github.com/apache/spark/pull/17529
[SPARK-20211][SQL]floor or ceil with a decimal that its `precision < scale` should be supported ## What changes were proposed in this pull request? `precision` in a decimal indicates the length of the arbitrary precision integer. Here are a few examples of numbers with the same scale, but different precision: - 12345 / 100000 = 0.12345 // scale = 5, precision = 5 - 12340 / 100000 = 0.1234 // scale = 5, precision = 4 - 1 / 100000 = 0.00001 // scale = 5, precision = 1 This PR fix a bug in floor and ceil in `org.apache.spark.sql.types.Decimal` that will throw a `Decimal scale (0) cannot be greater than precision (-2)` exception when `precision < scale`. Before the fix, the following SQL will throw exception: ``` select 1 > 0.0001 from tb select floor(0.0001) from tb select ceil(0.0001) from tb ``` ## How was this patch tested? Added unit tests. You can merge this pull request into a Git repository by running: $ git pull https://github.com/stanzhai/spark fix_decimal_precision Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/17529.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #17529 ---- commit 2b094b6e8fb1b0b8ae8bc89782305ac44d172ec3 Author: stanzhai <stanz...@outlook.com> Date: 2017-04-04T12:48:53Z fix decimal floor/ceil precision bug commit 2d60230b8344b391c3edfeec7c19ad1717e93710 Author: stanzhai <stanz...@outlook.com> Date: 2017-04-04T14:28:03Z add test case commit 61058b6e69802312bda35cdaf04a5b2af7dcd827 Author: stanzhai <stanz...@outlook.com> Date: 2017-04-04T15:02:54Z update test case ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org