Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ object MathUtils {
f
} catch {
case e: ArithmeticException =>
throw ExecutionErrors.arithmeticOverflowError(e.getMessage, hint, context)
// On JDK 25+, Math.*Exact may throw ArithmeticException without a message
val message = if (e.getMessage != null) e.getMessage else "Overflow"
throw ExecutionErrors.arithmeticOverflowError(message, hint, context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing here causes duplication, why not do it in ExecutionErrors.arithmeticOverflowError like #54514?

in addition, better to use lower case "overflow" to match the original JDK message style

}
}

Expand All @@ -103,7 +105,8 @@ object MathUtils {
|try {
| $evalCode
|} catch (ArithmeticException e) {
| throw QueryExecutionErrors.arithmeticOverflowError(e.getMessage(), "", $context);
| String msg = e.getMessage() != null ? e.getMessage() : "Overflow";
| throw QueryExecutionErrors.arithmeticOverflowError(msg, "", $context);
|}
|""".stripMargin
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ class CatalystTypeConvertersSuite extends SparkFunSuite with SQLHelper {
val errMsg = intercept[ArithmeticException] {
IntervalUtils.durationToMicros(Duration.ofSeconds(Long.MaxValue, Long.MaxValue))
}.getMessage
assert(errMsg.contains("long overflow"))
// On JDK 25+, Math.multiplyExact may throw ArithmeticException without a message
assert(errMsg == null || errMsg.contains("long overflow"))
}

test("SPARK-35726: Truncate java.time.Duration by fields of day-time interval type") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,8 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
null)
}.getCause
assert(e.isInstanceOf[ArithmeticException])
assert(e.getMessage.contains("long overflow"))
// On JDK 25+, Math.multiplyExact may throw ArithmeticException without a message
assert(e.getMessage == null || e.getMessage.contains("long overflow"))

checkEvaluation(
TimestampAddInterval(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@ class DateTimeUtilsSuite extends SparkFunSuite with Matchers with SQLHelper {
val msg = intercept[ArithmeticException] {
DateTimeUtils.localDateTimeToMicros(dt)
}.getMessage
assert(msg == "long overflow")
// On JDK 25+, Math.multiplyExact may throw ArithmeticException without a message
assert(msg == null || msg == "long overflow")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ class IntervalUtilsSuite extends SparkFunSuite with SQLHelper {
val errMsg = intercept[ArithmeticException] {
durationToMicros(Duration.ofDays(106751991 + 1))
}.getMessage
assert(errMsg.contains("long overflow"))
// On JDK 25+, Math.multiplyExact may throw ArithmeticException without a message
assert(errMsg == null || errMsg.contains("long overflow"))
}

test("SPARK-34615: period to months") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,10 @@ class TimestampFormatterSuite extends DatetimeFormatterSuite {
assert(formatter.parse("294247") === date(294247))
assert(formatter.parse("-290307") === date(-290307))
val e1 = intercept[ArithmeticException](formatter.parse("294248"))
assert(e1.getMessage === "long overflow")
// On JDK 25+, Math.multiplyExact may throw ArithmeticException without a message
assert(e1.getMessage == null || e1.getMessage === "long overflow")
val e2 = intercept[ArithmeticException](formatter.parse("-290308"))
assert(e2.getMessage === "long overflow")
assert(e2.getMessage == null || e2.getMessage === "long overflow")
}

test("SPARK-36418: default parsing w/o pattern") {
Expand Down