0lai0 commented on code in PR #4653:
URL: https://github.com/apache/datafusion-comet/pull/4653#discussion_r4283807323


##########
spark/src/test/scala/org/apache/comet/CometCodegenSuite.scala:
##########
@@ -2344,6 +2344,57 @@ class CometCodegenSuite
     }
   }
 
+  test("divide-by-zero through dispatched ScalaUDF surfaces 
SparkArithmeticException (#4517)") {
+    // When a ScalaUDF is dispatched into the native plan and the outer 
expression divides
+    // by the UDF result, the error must surface as 
SparkArithmeticException(DIVIDE_BY_ZERO),
+    // not as CometNativeException.  Verifies the JNI bridge correctly unwraps 
the
+    // DataFusion error chain even when DataFusion 53+ wraps it in 
Context/External layers.
+    assertDispatchedUdfArithmeticError("SELECT 1 / identity_int(a) FROM t", 
"DIVIDE_BY_ZERO")
+  }
+
+  test("integer overflow through dispatched ScalaUDF surfaces 
SparkArithmeticException (#4517)") {
+    // Same path as the divide-by-zero case, but a different SparkError 
variant, so a
+    // misclassification in the JNI bridge cannot pass both tests.
+    assertDispatchedUdfArithmeticError(
+      "SELECT identity_int(a) + 2147483647 FROM t",
+      "ARITHMETIC_OVERFLOW")
+  }
+
+  /**
+   * Runs `query` over `t (a INT)` holding 0 and 1 with ANSI enabled, where 
the query applies
+   * native arithmetic to the result of the dispatched ScalaUDF 
`identity_int`, and asserts the
+   * failure surfaces as `SparkArithmeticException` carrying `errorClass`.
+   */
+  private def assertDispatchedUdfArithmeticError(query: String, errorClass: 
String): Unit = {

Review Comment:
   Switched to `assertCodegenRan { checkSparkError(sql(query), errorClass) }`. 
You're right, both tests pass on main: the projection path doesn't wrap the 
error, so the regression coverage is the Rust tests and the description now 
says so. I kept them as end-to-end coverage of the dispatched UDF path, but 
happy to drop them if you'd rather avoid the overlap with` 
expect_error_class.sql`.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to