You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2022/08/24 12:14:22 UTC

[spark] branch master updated: [SPARK-40203][SQL][TESTS] Add test cases for Decimal

This is an automated email from the ASF dual-hosted git repository.

maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 26b4828c4e3 [SPARK-40203][SQL][TESTS] Add test cases for Decimal
26b4828c4e3 is described below

commit 26b4828c4e34b76ca435ab6b4e074b8828531e1b
Author: Jiaan Geng <be...@163.com>
AuthorDate: Wed Aug 24 15:13:50 2022 +0300

    [SPARK-40203][SQL][TESTS] Add test cases for Decimal
    
    ### What changes were proposed in this pull request?
    Recently, I find that some operators of Spark Decimal missing unit tests. e.g. quot, negate, abs, floor, ceil.
    
    This PR adds test cases for these operators of Spark Decimal missing unit tests.
    
    ### Why are the changes needed?
    Spark Decimal have a lot of methods without unit tests.
    
    ### Does this PR introduce _any_ user-facing change?
    'No'.
    Just add test cases.
    
    ### How was this patch tested?
    New test cases.
    
    Closes #37644 from beliefer/SPARK-40203.
    
    Authored-by: Jiaan Geng <be...@163.com>
    Signed-off-by: Max Gekk <ma...@gmail.com>
---
 .../org/apache/spark/sql/types/DecimalSuite.scala   | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DecimalSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DecimalSuite.scala
index 95e1f832821..b388dc46aa2 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DecimalSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DecimalSuite.scala
@@ -201,6 +201,27 @@ class DecimalSuite extends SparkFunSuite with PrivateMethodTester with SQLHelper
     assert(Decimal(10, 2, 0) - Decimal(-90, 2, 0) === Decimal(100, 3, 0))
   }
 
+  test("quot") {
+    assert(Decimal(100).quot(Decimal(100)) === Decimal(BigDecimal("1")))
+    assert(Decimal(100).quot(Decimal(33)) === Decimal(BigDecimal("3")))
+    assert(Decimal(100).quot(Decimal(-100)) === Decimal(BigDecimal("-1")))
+    assert(Decimal(100).quot(Decimal(-33)) === Decimal(BigDecimal("-3")))
+  }
+
+  test("negate & abs") {
+    assert(-Decimal(100) === Decimal(BigDecimal("-100")))
+    assert(-Decimal(-100) === Decimal(BigDecimal("100")))
+    assert(Decimal(100).abs === Decimal(BigDecimal("100")))
+    assert(Decimal(-100).abs === Decimal(BigDecimal("100")))
+  }
+
+  test("floor & ceil") {
+    assert(Decimal("10.03").floor === Decimal(BigDecimal("10")))
+    assert(Decimal("10.03").ceil === Decimal(BigDecimal("11")))
+    assert(Decimal("-10.03").floor === Decimal(BigDecimal("-11")))
+    assert(Decimal("-10.03").ceil === Decimal(BigDecimal("-10")))
+  }
+
   // regression test for SPARK-8359
   test("accurate precision after multiplication") {
     val decimal = (Decimal(Long.MaxValue, 38, 0) * Decimal(Long.MaxValue, 38, 0)).toJavaBigDecimal


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org