Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down