Skip to content

Commit 09712e1

Browse files
committed
Fix:Add unit test case
1 parent 9b6dab8 commit 09712e1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ class MathExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
546546
val bdResults: Seq[BigDecimal] = Seq(BigDecimal(3.0), BigDecimal(3.1), BigDecimal(3.14),
547547
BigDecimal(3.142), BigDecimal(3.1416), BigDecimal(3.14159),
548548
BigDecimal(3.141593), BigDecimal(3.1415927))
549-
// round_scale > current_scale would result in precision increase
550-
// and not allowed by o.a.s.s.types.Decimal.changePrecision, therefore null
549+
551550
(0 to 7).foreach { i =>
552551
checkEvaluation(Round(bdPi, i), bdResults(i), EmptyRow)
553552
checkEvaluation(BRound(bdPi, i), bdResults(i), EmptyRow)

sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,19 @@ class MathFunctionsSuite extends QueryTest with SharedSQLContext {
231231
Seq(Row(BigDecimal("0E3"), BigDecimal("0E2"), BigDecimal("0E1"), BigDecimal(3),
232232
BigDecimal("3.1"), BigDecimal("3.14"), BigDecimal("3.142")))
233233
)
234+
235+
val bdPi: BigDecimal = BigDecimal(31415925L, 7)
236+
checkAnswer(
237+
sql(s"SELECT round($bdPi, 7), round($bdPi, 8), round($bdPi, 9), round($bdPi, 10), " +
238+
s"round($bdPi, 100), round($bdPi, 6), round(null, 8)"),
239+
Seq(Row(bdPi, bdPi, bdPi, bdPi, bdPi, BigDecimal("3.141593"), null))
240+
)
241+
242+
checkAnswer(
243+
sql(s"SELECT bround($bdPi, 7), bround($bdPi, 8), bround($bdPi, 9), bround($bdPi, 10), " +
244+
s"bround($bdPi, 100), bround($bdPi, 6), bround(null, 8)"),
245+
Seq(Row(bdPi, bdPi, bdPi, bdPi, bdPi, BigDecimal("3.141592"), null))
246+
)
234247
}
235248

236249
test("round/bround with data frame from a local Seq of Product") {

0 commit comments

Comments
 (0)