You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2016/01/05 06:05:31 UTC

spark git commit: [SPARK-12600][SQL] follow up: add range check for DecimalType

Repository: spark
Updated Branches:
  refs/heads/master 8896ec9f0 -> b634901bb


[SPARK-12600][SQL] follow up: add range check for DecimalType

This addresses davies' code review feedback in https://github.com/apache/spark/pull/10559

Author: Reynold Xin <rx...@databricks.com>

Closes #10586 from rxin/remove-deprecated-sql-followup.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/b634901b
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/b634901b
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/b634901b

Branch: refs/heads/master
Commit: b634901bb28070ac5d9a24a9bc7b7640472a54e2
Parents: 8896ec9
Author: Reynold Xin <rx...@databricks.com>
Authored: Mon Jan 4 21:05:27 2016 -0800
Committer: Reynold Xin <rx...@databricks.com>
Committed: Mon Jan 4 21:05:27 2016 -0800

----------------------------------------------------------------------
 .../scala/org/apache/spark/sql/types/DecimalType.scala    | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/b634901b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala
index fdae2e8..cf53221 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala
@@ -20,6 +20,7 @@ package org.apache.spark.sql.types
 import scala.reflect.runtime.universe.typeTag
 
 import org.apache.spark.annotation.DeveloperApi
+import org.apache.spark.sql.AnalysisException
 import org.apache.spark.sql.catalyst.ScalaReflectionLock
 import org.apache.spark.sql.catalyst.expressions.Expression
 
@@ -39,6 +40,15 @@ import org.apache.spark.sql.catalyst.expressions.Expression
 @DeveloperApi
 case class DecimalType(precision: Int, scale: Int) extends FractionalType {
 
+  if (scale > precision) {
+    throw new AnalysisException(
+      s"Decimal scale ($scale) cannot be greater than precision ($precision).")
+  }
+
+  if (precision > DecimalType.MAX_PRECISION) {
+    throw new AnalysisException(s"DecimalType can only support precision up to 38")
+  }
+
   // default constructor for Java
   def this(precision: Int) = this(precision, 0)
   def this() = this(10)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org