mickjermsurawong-stripe commented on a change in pull request #25033:
[SPARK-28224][SQL] Check overflow in decimal Sum aggregate
URL: https://github.com/apache/spark/pull/25033#discussion_r314953309
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
##########
@@ -156,6 +156,33 @@ class DataFrameSuite extends QueryTest with
SharedSQLContext {
structDf.select(xxhash64($"a", $"record.*")))
}
+ test("SPARK-28224: Aggregate sum big decimal overflow") {
+ Seq(true, false).foreach { nullOnOverflow =>
+ withSQLConf((SQLConf.DECIMAL_OPERATIONS_NULL_ON_OVERFLOW.key,
nullOnOverflow.toString)) {
+ val structDf = largeDecimals.select("a").agg(sum("a"))
+ if (nullOnOverflow) {
+ checkAnswer(structDf, Row(null))
+ } else {
+ val e = intercept[Exception] {
+ structDf.collect
+ }
+ assert(e.getCause.getClass.equals(classOf[ArithmeticException]))
+ assert(e.getCause.getMessage.contains("cannot be represented as
Decimal"))
+ }
+ }
+ }
+ }
+
+ test("Aggregate sum integers") {
Review comment:
@maropu the change introduces branching for BigDecimal case, so I want to
verify that sum still works for integer/double case.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]