You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by ch...@apache.org on 2026/04/15 11:17:52 UTC
(gluten) 29/29: [GLUTEN-10134][VL] Fix Spark 4.0 compilation: use reflection for remainderByZeroError
This is an automated email from the ASF dual-hosted git repository.
changchen pushed a commit to branch feature/ansi-ci-baseline
in repository https://gitbox.apache.org/repos/asf/gluten.git
commit 4755345e4c5501ac7fd81da4e5f1adc18065c993
Author: Chang chen <ch...@microsoft.com>
AuthorDate: Wed Apr 15 11:17:07 2026 +0000
[GLUTEN-10134][VL] Fix Spark 4.0 compilation: use reflection for remainderByZeroError
QueryExecutionErrors.remainderByZeroError was added in Spark 4.1 and does
not exist in Spark 4.0. Use reflection to call it when available, falling
back to divideByZeroError on Spark 4.0.
Co-Authored-By: Claude Opus 4 <no...@anthropic.com>
---
.../spark/sql/VeloxCastExceptionTranslator.scala | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/gluten-arrow/src/main/scala/org/apache/spark/sql/VeloxCastExceptionTranslator.scala b/gluten-arrow/src/main/scala/org/apache/spark/sql/VeloxCastExceptionTranslator.scala
index de44402cc5..f1236899c2 100644
--- a/gluten-arrow/src/main/scala/org/apache/spark/sql/VeloxCastExceptionTranslator.scala
+++ b/gluten-arrow/src/main/scala/org/apache/spark/sql/VeloxCastExceptionTranslator.scala
@@ -169,10 +169,30 @@ object VeloxCastExceptionTranslator {
private val ContextLineRegex: Regex =
"""(?m)^Context:.*?(checked_remainder|checked_modulus)""".r
+ // Spark 4.1 added remainderByZeroError; Spark 4.0 only has divideByZeroError.
+ // Use reflection to call remainderByZeroError if available, fallback to divideByZeroError.
+ private val remainderByZeroMethod: Option[java.lang.reflect.Method] = {
+ try {
+ val methods = QueryExecutionErrors.getClass.getMethods
+ methods.find(m => m.getName == "remainderByZeroError" && m.getParameterCount == 1)
+ } catch {
+ case _: Exception => None
+ }
+ }
+
+ private def createRemainderByZeroError(): ArithmeticException = {
+ remainderByZeroMethod match {
+ case Some(m) =>
+ m.invoke(QueryExecutionErrors, null.asInstanceOf[AnyRef]).asInstanceOf[ArithmeticException]
+ case None =>
+ QueryExecutionErrors.divideByZeroError(null)
+ }
+ }
+
private def translateArithmetic(reason: String, fullMsg: String): Option[RuntimeException] = {
if (DivisionByZeroRegex.findFirstIn(reason).isDefined) {
if (ContextLineRegex.findFirstIn(fullMsg).isDefined) {
- Some(QueryExecutionErrors.remainderByZeroError(null))
+ Some(createRemainderByZeroError())
} else {
Some(QueryExecutionErrors.divideByZeroError(null))
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org