Copilot commented on code in PR #12502:
URL: https://github.com/apache/gluten/pull/12502#discussion_r3575387973


##########
gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala:
##########
@@ -16,6 +16,25 @@
  */
 package org.apache.spark.sql.execution
 
+import org.apache.spark.SparkThrowable
 import org.apache.spark.sql.GlutenSQLTestsTrait
 
-class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with 
GlutenSQLTestsTrait {}
+class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with 
GlutenSQLTestsTrait {
+
+  // Velox returns a native FILE_NOT_FOUND error instead of Spark's structured 
error condition.
+  override def checkErrorMatchPVals(
+      exception: SparkThrowable,
+      condition: String,
+      parameters: Map[String, String]): Unit = {
+    if (condition == "FAILED_READ_FILE.FILE_NOT_EXIST") {
+      val messages = Iterator
+        .iterate[Throwable](exception.asInstanceOf[Throwable])(_.getCause)
+        .takeWhile(_ != null)
+        .flatMap(error => Option(error.getMessage))
+
+      assert(messages.exists(_.contains("FILE_NOT_FOUND")))
+    } else {
+      super.checkErrorMatchPVals(exception, condition, parameters)
+    }

Review Comment:
   `SparkThrowable` is unconditionally cast to `Throwable` to walk the cause 
chain. If Spark ever calls this helper with a non-`Throwable` `SparkThrowable`, 
this will fail with `ClassCastException` and obscure the underlying error. It’s 
safer to pattern-match on `Throwable` and fall back to `super`, and also 
materialize the collected messages so the assertion can print them for 
debugging.



##########
gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala:
##########
@@ -16,6 +16,25 @@
  */
 package org.apache.spark.sql.execution
 
+import org.apache.spark.SparkThrowable
 import org.apache.spark.sql.GlutenSQLTestsTrait
 
-class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with 
GlutenSQLTestsTrait {}
+class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with 
GlutenSQLTestsTrait {
+
+  // Velox returns a native FILE_NOT_FOUND error instead of Spark's structured 
error condition.
+  override def checkErrorMatchPVals(
+      exception: SparkThrowable,
+      condition: String,
+      parameters: Map[String, String]): Unit = {
+    if (condition == "FAILED_READ_FILE.FILE_NOT_EXIST") {
+      val messages = Iterator
+        .iterate[Throwable](exception.asInstanceOf[Throwable])(_.getCause)
+        .takeWhile(_ != null)
+        .flatMap(error => Option(error.getMessage))
+
+      assert(messages.exists(_.contains("FILE_NOT_FOUND")))
+    } else {
+      super.checkErrorMatchPVals(exception, condition, parameters)
+    }

Review Comment:
   `SparkThrowable` is unconditionally cast to `Throwable` to walk the cause 
chain. If Spark ever calls this helper with a non-`Throwable` `SparkThrowable`, 
this will fail with `ClassCastException` and obscure the underlying error. It’s 
safer to pattern-match on `Throwable` and fall back to `super`, and also 
materialize the collected messages so the assertion can print them for 
debugging.



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