Skip to content

Commit 9c64a75

Browse files
committed
[SPARK-9060] [SQL] Revert SPARK-8359, SPARK-8800, and SPARK-8677
JIRA: https://issues.apache.org/jira/browse/SPARK-9060 This PR reverts: * apache@31bd306 (SPARK-8359) * apache@24fda73 (SPARK-8677) * apache@4b5cfc9 (SPARK-8800) Author: Yin Huai <[email protected]> Closes apache#7426 from yhuai/SPARK-9060 and squashes the following commits: 651264d [Yin Huai] Revert "[SPARK-8359] [SQL] Fix incorrect decimal precision after multiplication" cfda7e4 [Yin Huai] Revert "[SPARK-8677] [SQL] Fix non-terminating decimal expansion for decimal divide operation" 2de9afe [Yin Huai] Revert "[SPARK-8800] [SQL] Fix inaccurate precision/scale of Decimal division operation"
1 parent 73d92b0 commit 9c64a75

File tree

2 files changed

+2
-37
lines changed

2 files changed

+2
-37
lines changed

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.apache.spark.sql.types
1919

20-
import java.math.{MathContext, RoundingMode}
21-
2220
import org.apache.spark.annotation.DeveloperApi
2321

2422
/**
@@ -138,14 +136,6 @@ final class Decimal extends Ordered[Decimal] with Serializable {
138136
}
139137

140138
def toBigDecimal: BigDecimal = {
141-
if (decimalVal.ne(null)) {
142-
decimalVal(MathContext.UNLIMITED)
143-
} else {
144-
BigDecimal(longVal, _scale)(MathContext.UNLIMITED)
145-
}
146-
}
147-
148-
def toLimitedBigDecimal: BigDecimal = {
149139
if (decimalVal.ne(null)) {
150140
decimalVal
151141
} else {
@@ -273,15 +263,8 @@ final class Decimal extends Ordered[Decimal] with Serializable {
273263

274264
def * (that: Decimal): Decimal = Decimal(toBigDecimal * that.toBigDecimal)
275265

276-
def / (that: Decimal): Decimal = {
277-
if (that.isZero) {
278-
null
279-
} else {
280-
// To avoid non-terminating decimal expansion problem, we get scala's BigDecimal with limited
281-
// precision and scala.
282-
Decimal(toLimitedBigDecimal / that.toLimitedBigDecimal)
283-
}
284-
}
266+
def / (that: Decimal): Decimal =
267+
if (that.isZero) null else Decimal(toBigDecimal / that.toBigDecimal)
285268

286269
def % (that: Decimal): Decimal =
287270
if (that.isZero) null else Decimal(toBigDecimal % that.toBigDecimal)

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,4 @@ class DecimalSuite extends SparkFunSuite with PrivateMethodTester {
171171
assert(new Decimal().set(100L, 10, 0).toUnscaledLong === 100L)
172172
assert(Decimal(Long.MaxValue, 100, 0).toUnscaledLong === Long.MaxValue)
173173
}
174-
175-
test("accurate precision after multiplication") {
176-
val decimal = (Decimal(Long.MaxValue, 38, 0) * Decimal(Long.MaxValue, 38, 0)).toJavaBigDecimal
177-
assert(decimal.unscaledValue.toString === "85070591730234615847396907784232501249")
178-
}
179-
180-
test("fix non-terminating decimal expansion problem") {
181-
val decimal = Decimal(1.0, 10, 3) / Decimal(3.0, 10, 3)
182-
// The difference between decimal should not be more than 0.001.
183-
assert(decimal.toDouble - 0.333 < 0.001)
184-
}
185-
186-
test("fix loss of precision/scale when doing division operation") {
187-
val a = Decimal(2) / Decimal(3)
188-
assert(a.toDouble < 1.0 && a.toDouble > 0.6)
189-
val b = Decimal(1) / Decimal(8)
190-
assert(b.toDouble === 0.125)
191-
}
192174
}

0 commit comments

Comments
 (0)