GitHub user dongjoon-hyun opened a pull request: https://github.com/apache/spark/pull/13358
[SPARK-15612][SQL] Raise exception if decimal `scale` >= `precision` ## What changes were proposed in this pull request? Currently, Spark raises exceptions only when decimal `scale` > `precision`. However, the value becames `null` if `scale` = `precision`. We should raise exceptions for that case, too. **Before** ```scala scala> sql("select cast('1' as Decimal(2,1))") res0: org.apache.spark.sql.DataFrame = [CAST(1 AS DECIMAL(2,1)): decimal(2,1)] scala> sql("select cast('1' as Decimal(2,2))") res1: org.apache.spark.sql.DataFrame = [CAST(1 AS DECIMAL(2,2)): decimal(2,2)] scala> sql("select cast('1' as Decimal(2,3))") org.apache.spark.sql.catalyst.parser.ParseException: Decimal scale (3) cannot be greater than precision (2). scala> sql("select cast('1' as Decimal(2,1))").head res2: org.apache.spark.sql.Row = [1.0] scala> sql("select cast('1' as Decimal(2,2))").head res3: org.apache.spark.sql.Row = [null] ``` **After** ```scala scala> sql("select cast('1' as Decimal(2,1))") res0: org.apache.spark.sql.DataFrame = [CAST(1 AS DECIMAL(2,1)): decimal(2,1)] scala> sql("select cast('1' as Decimal(2,2))") org.apache.spark.sql.catalyst.parser.ParseException: Decimal scale (2) must be less than precision (2). ``` ## How was this patch tested? Pass the Jenkins tests (with a new testcase) You can merge this pull request into a Git repository by running: $ git pull https://github.com/dongjoon-hyun/spark SPARK-15612 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/13358.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 #13358 ---- commit 03e76984fbf702e067ae3ee4b2aee88a0f94e23e Author: Dongjoon Hyun <dongj...@apache.org> Date: 2016-05-27T10:24:58Z [SPARK-15612][SQL] Raise exception if decimal `scale` >= `precision` ---- --- 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