Skip to content

Commit cb7ada1

Browse files
viiryarxin
authored andcommitted
[SPARK-8342][SQL] Fix Decimal setOrNull
JIRA: https://issues.apache.org/jira/browse/SPARK-8342 Author: Liang-Chi Hsieh <[email protected]> Closes apache#6797 from viirya/fix_decimal and squashes the following commits: 8a447b1 [Liang-Chi Hsieh] Add unit test. d67a5ea [Liang-Chi Hsieh] Merge remote-tracking branch 'upstream/master' into fix_decimal ab6d8af [Liang-Chi Hsieh] Fix setOrNull.
1 parent 35d1267 commit cb7ada1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ final class Decimal extends Ordered[Decimal] with Serializable {
8686
if (precision < 19) {
8787
return null // Requested precision is too low to represent this value
8888
}
89-
this.decimalVal = BigDecimal(longVal)
89+
this.decimalVal = BigDecimal(unscaled)
9090
this.longVal = 0L
9191
} else {
9292
val p = POW_10(math.min(precision, MAX_LONG_DIGITS))

sql/catalyst/src/test/scala/org/apache/spark/sql/types/decimal/DecimalSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,10 @@ class DecimalSuite extends SparkFunSuite with PrivateMethodTester {
156156
assert(Decimal(-100) % Decimal(3) === Decimal(-1))
157157
assert(Decimal(100) % Decimal(0) === null)
158158
}
159+
160+
test("set/setOrNull") {
161+
assert(new Decimal().set(10L, 10, 0).toUnscaledLong === 10L)
162+
assert(new Decimal().set(100L, 10, 0).toUnscaledLong === 100L)
163+
assert(Decimal(Long.MaxValue, 100, 0).toUnscaledLong === Long.MaxValue)
164+
}
159165
}

0 commit comments

Comments
 (0)