LuciferYang commented on a change in pull request #22149: 
[SPARK-25158][SQL]Executor accidentally exit because 
ScriptTransformationWriterThread throw Exception.
URL: https://github.com/apache/spark/pull/22149#discussion_r255429827
 
 

 ##########
 File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
 ##########
 @@ -2348,4 +2348,36 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
     }
   }
 
+  test("SPARK-25158: " +
+    "Executor accidentally exit because ScriptTransformationWriterThread throw 
Exception") {
+    withTempView("test") {
+      val defaultUncaughtExceptionHandler = 
Thread.getDefaultUncaughtExceptionHandler
+      try {
+        val uncaughtExceptionHandler = new TestUncaughtExceptionHandler
+        Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler)
+
+        // Use a bad udf to generate failed inputs.
+        import org.apache.spark.sql.functions.udf
+        val badUDF = udf({x: Int =>
+          if (x < 1) x
+          else throw new RuntimeException("Failed to produce data.")
+          })
+        spark
+          .range(5)
+          .select(badUDF('id).as("a"))
+          .createOrReplaceTempView("test")
+        val scriptFilePath = getTestResourcePath("data")
+        val e = intercept[SparkException] {
+          sql(
+            s"""FROM test SELECT TRANSFORM(a)
+               |USING 'python $scriptFilePath/scripts/test_transform.py "\t"'
+             """.stripMargin).collect()
+        }
+        assert(e.getMessage.contains("Failed to produce data."))
 
 Review comment:
   Keep `throw t`, `TestUncaughtExceptionHandler` will catch a `SparkException`.
   Keep `throw t` and not  set  `TestUncaughtExceptionHandler` as 
DefaultUncaughtExceptionHandler,  this case always success but we can see log 
as follwing:
   ```
   ERROR org.apache.spark.util.Utils: Uncaught exception in thread 
Thread-ScriptTransformation-Feed
   ```
   and the Uncaught exception will catch by `SparkUncaughtExceptionHandler` in 
non local model. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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]

Reply via email to