Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kiszk committed Apr 19, 2017
1 parent 74aa0df commit 9a15ba2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ final class Decimal extends Ordered[Decimal] with Serializable {
* Set this Decimal to the given BigInteger value. Will have precision 38 and scale 0.
*/
def set(bigintval: BigInteger): Decimal = {
this.decimalVal = null
this.longVal = bigintval.longValueExact()
this._precision = DecimalType.MAX_PRECISION
this._scale = 0
this
try {
this.decimalVal = null
this.longVal = bigintval.longValueExact()
this._precision = DecimalType.MAX_PRECISION
this._scale = 0
this
} catch {
case _: ArithmeticException =>
set(BigDecimal(bigintval))
this
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,10 @@ class DecimalSuite extends SparkFunSuite with PrivateMethodTester {
}
}
}

test("SPARK-20341: support BigInt's value does not fit in long value range") {
val bigInt = scala.math.BigInt("9223372036854775808")
val decimal = Decimal.apply(bigInt)
assert(decimal.toJavaBigDecimal.unscaledValue.toString === "9223372036854775808")
}
}

0 comments on commit 9a15ba2

Please sign in to comment.